Volt compiled dir

163 views
Skip to first unread message

Andres-Gutierrez

unread,
Oct 23, 2012, 2:04:04 PM10/23/12
to phalcon-...@googlegroups.com
Hi,

I'm looking for the best way to add a "compiled path" to Volt

Let's pretend this is the volt template
apps/
  views/
    index/
      show.volt

Currently it appends a ".php" to the template path to create the PHP plain version of the template:

//Using the same directory
apps/views/index/show.volt.php

But using a compiled directory:

//Using an alternative directory with the same structure
cache/
   apps/
     views/
        index/
          show.volt.php

This needs that Phalcon creates the whole directory structure, adding more filesystem overhead

//Using a hash (md5, sha1, etc)
cache/
   58b9e70b65a77700ba66e9c64d6b9f89

This also adds more overhead because the framework needs to calculate the hash in every request (also for each template rendered)

//Replacing the Directory Separator by other char (example / by _)
cache/apps_views_index_show.volt.php

This is faster but some file name collisions may be presented if the template name contains the "_" character.

Any thoughts?

     
 

Nikolaos Dimopoulos

unread,
Oct 23, 2012, 2:49:29 PM10/23/12
to Andres-Gutierrez, phalcon-...@googlegroups.com
The magic percent %

cache/
   apps/
     views/
        index/
          show.volt.php

can become

%%apps%%views%%index%%%show.volt.php

%folder% followed by %folder% and all of it enclosed in an additional %%.






The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.




     
 

--
 
 

Wojtek Gancarczyk

unread,
Oct 24, 2012, 3:52:42 AM10/24/12
to phalcon-...@googlegroups.com, andres.g...@phalconphp.com
Hi,

I would look at it from different perspective. When I develop in my local environment I don't care about the small overhead of creating paths where the cached/compiled views will be placed. Production environment is a different story. Assuming that the view templates don't have to be recompiled every hour/day/month (changing them would require a new deployment), I would like to have a way of compiling them once during build/deployment phase. This way Phalcon can assume that he can find a compiled template always at a certain place without the need to compile it again. What do you think?

Best
Wojtek

Nikolaos Dimopoulos

unread,
Oct 24, 2012, 9:06:51 AM10/24/12
to Wojtek Gancarczyk, phalcon-...@googlegroups.com, andres.g...@phalconphp.com
Let me get this correctly.

  1. Developer creates app. Does NOT set compile directory for volt
    - Does the app complain? or do the compiled templates exist in the same folder as the view?
  2. Developer creates app. Sets compile directory for volt
    - Application creates volt templates on demand i.e. the first time the template is accessed it gets created and reused after that
  3. Developer creates app - deploys it (volt used with compile directory)
    - Ability to call \Phalcon\Utilities::compileVolt() from the CLI or somehow to run and compile all the templates.
Does the above pretty much sums it up?


The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.


--
 
 

Wojtek Gancarczyk

unread,
Oct 24, 2012, 9:14:53 AM10/24/12
to phalcon-...@googlegroups.com, Wojtek Gancarczyk, andres.g...@phalconphp.com
1. App complains. You need to set up a directory where the compiled templates should be created. Alternatively default directory could be the same as the template directory to reduce the configuration to minimum.
2. Correct
3. Correct, however. If template not found it should be compiled anyway. Developer should take care of pre-compiling the templates, but nobody's perfect :)

Nikolaos Dimopoulos

unread,
Oct 24, 2012, 9:34:48 AM10/24/12
to Wojtek Gancarczyk, phalcon-...@googlegroups.com, andres.g...@phalconphp.com
Got it thanks Wojtek

I can see the challenges. No write access by the web server would definitely be a killer - when the app compiles the templates on the fly. The compile folder could definitely help there but yes the need to compile the templates from the CLI would be great

If this is not a quick fix, we will have to push it to a later build.

Nikos

The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.


--
 
 

Andres-Gutierrez

unread,
Oct 24, 2012, 11:03:28 AM10/24/12
to Nikolaos Dimopoulos, Wojtek Gancarczyk, phalcon-...@googlegroups.com
This is how currently works:

1. The .php extension is appended to the actual path to produce the compiled PHP apps/x/views/a.volt and apps/x/views/a.volt.php
2. There is a option "stat", like the APC stat, it checks for changes in the template file to re-compile the template again
3. This already can be done: https://github.com/phalcon/cphalcon/blob/0.6.0/unit-tests/ViewEnginesVoltTest.php#L711

this is the related docs: http://docs.phalconphp.com/en/0.6.0/reference/volt.html#setting-up-the-volt-engine

2012/10/24 Nikolaos Dimopoulos <ni...@niden.net>
--
 
 

Reply all
Reply to author
Forward
0 new messages