Re: [SMARTY-DEV] More accurate compiled file names

From: Date: Mon, 31 May 2004 06:17:12 +0000
Subject: Re: [SMARTY-DEV] More accurate compiled file names
References: 1 2 3  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2340@lists.php.net to get a copy of this message
On Mon, May 31, 2004 at 12:28:31AM +0400, Dmitry Koteroff wrote: > I know about crc32(). Let's see code: > > - // make source name safe for filename > - $_filename = urlencode(basename($auto_source)); > - $_crc32 = crc32($auto_source) . $_compile_dir_sep; > - // prepend %% to avoid name conflicts with > - // with $params['auto_id'] names > - $_crc32 = '%%' . substr($_crc32,0,3) . $_compile_dir_sep . > '%%' . $_crc32; > - $_return .= $_crc32 . $_filename; > > Please consider using of basename() function! Pathname is NOT > included in the cache filename. I am talking about that, ant > attached patch solves this - uses full path instead of crc32() > (or in addition to it). > > Use_sub_dirs does not makes Smarty to consider full path. It does > other thing - it improves (theoretically) performance. yes. FWIW: Smarty-2.5.0 behaves differently than 2.6.2 does: with use_sub_dirs=true it behaves like 2.6.2, but with use_sub_dirs=false it behaves as you propose: no crc32-numbers in the compiled-template-name, but something like ^full^path^to^template.tpl . I like the behaviour of 2.5.0 more than it is now and would like to see it reverted. > -- > Best regards, > Dmitry Koteroff. > > RA> Hi, > > RA> The compiled templates are saved in filenames that reflect their filename > RA> and content. > > RA> The numbers you see there are the result of a crc32() on the contents of > RA> the file (see http://www.php.net/crc32). This is taken > RA> to ensure that each > RA> filename is unique, so that two templates called "header.tpl" in different > RA> locations do not overwrite each others compiled template file. > > RA> so a file like %%-13/%%-135052920/header.tpl.php should be perfectly > RA> understandable as the compiled template for "header.tpl" > > RA> The filenames are split into directories so that on larger smarty > RA> installations, there is no filesystem delay trying to access the files. If > RA> you do not wish to use directories, simply ensure that > RA> $smarty->use_sub_dirs = false and Smarty will automatically substitute / > RA> for ^ in your compiled template files. > > RA> Hope this helps. > > RA> Regards, > RA> -bok > > RA> At 08:31 AM 30/05/2004, you wrote: > >>Hello. > >> > >>Smarty saves its compiled code to files with unreadable names > >>(like %%23t2763%%sjhdjsdhjshgd.php). It makes too difficult to > >>find fatal error in the template (for example, {$obj->spoon()}, > >>where spoon is non-existent method). > >> > >>Attached patch corrects this problem - it replaces "/" by "^" and > >>saves the file to temporary location. > >> > >>Replacement code: > >> > >>$_filename = preg_replace("{[/\\\\]}s", "^", $_filename); > >>$_filename = preg_replace("{[^a-z0-9~!_=.^-]}si", "_", $_filename); > >> > >>Don't you plan to insert this patch to production version? > >> > >>-- > >>Best regards, > >> Dmitry Koteroff. > >>-- > >>Smarty Development Mailing List (http://smarty.php.net/) > >>To unsubscribe, visit: http://www.php.net/unsub.php > > -- > Smarty Development Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.dev (#2340) next »