|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
Making Smarty's cache HTTP header awareHi,
Currently, when Smarty caches content it has no knowledge of the HTTP headers that the script served to the client. In the case where the cache is cleared and the action sends special HTTP headers to the client, those HTTP headers only get sent on the first response and subsequent responses read from the cache and don't send the HTTP headers. PHP5 provides the headers_list() function, so I've modified Smarty to include that information in the cache meta-data and pass those headers onto the client it when the headers are available in the meta-data. This feature is PHP5 only, but will not break PHP4 code. Attached is the changes I made against Smarty 2.6.18. I'd appreciate consideration for adding these changes to the Smarty core. Thanks, Luke Baker -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awareOn 07/11/2007, Luke Baker <lukebaker@...> wrote:
> Attached is the changes I made against Smarty 2.6.18. I'd appreciate > consideration for adding these changes to the Smarty core. There is no attachment, sorry. Hielke -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awareHielke Hoeve schrieb:
> On 07/11/2007, Luke Baker <lukebaker@...> wrote: >> Attached is the changes I made against Smarty 2.6.18. I'd appreciate >> consideration for adding these changes to the Smarty core. > > There is no attachment, sorry. i remember, in teh past patches that do add functionality for only a specific PHP version where not accepted, did Smarty devs changed this policy? (beside th fact that i did never understood why) -- Sebastian -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awareOn Thu, Nov 08, 2007 at 09:30:12AM +0100, Sebastian Mendel wrote:
> Hielke Hoeve schrieb: > > On 07/11/2007, Luke Baker <lukebaker@...> wrote: > >> Attached is the changes I made against Smarty 2.6.18. I'd appreciate > >> consideration for adding these changes to the Smarty core. > > > > There is no attachment, sorry. > > i remember, in teh past patches that do add functionality for only a > specific PHP version where not accepted, did Smarty devs changed this policy? > > (beside th fact that i did never understood why) Smarty-2.x requires php-4.0.6 or later. this requirement has never been weakened. -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awaremessju mohr schrieb:
> On Thu, Nov 08, 2007 at 09:30:12AM +0100, Sebastian Mendel wrote: >> Hielke Hoeve schrieb: >>> On 07/11/2007, Luke Baker <lukebaker@...> wrote: >>>> Attached is the changes I made against Smarty 2.6.18. I'd appreciate >>>> consideration for adding these changes to the Smarty core. >>> There is no attachment, sorry. >> i remember, in teh past patches that do add functionality for only a >> specific PHP version where not accepted, did Smarty devs changed this policy? >> >> (beside th fact that i did never understood why) > > Smarty-2.x requires php-4.0.6 or later. this requirement has never been weakened. i was not talking about Smarty requirements, i was talking about features working only with specific versions of PHP like the above mentioned -- Sebastian -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awareAh yes, here's the text of the patch. This is just an added bonus
feature for people using PHP5. If applied, Smarty will still work as before with earlier PHP versions. Luke Index: internals/core.write_cache_file.php =================================================================== --- internals/core.write_cache_file.php +++ internals/core.write_cache_file.php @@ -60,6 +60,9 @@ $params['results'] = implode('', $results); } $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials; + if (version_compare('5', phpversion(), "<") && function_exists('headers_list')) { + $smarty->_cache_info['headers'] = headers_list(); + } // prepend the cache header info into cache file $_cache_info = serialize($smarty->_cache_info); Index: Smarty.class.php =================================================================== --- Smarty.class.php +++ Smarty.class.php @@ -1212,10 +1212,18 @@ header('HTTP/1.1 304 Not Modified'); } else { + if (isset($this->_cache_info['headers'])) { + foreach ($this->_cache_info['headers'] as $h) + header($h); + } header('Last-Modified: '.$_gmt_mtime); echo $_smarty_results; } } else { + if (isset($this->_cache_info['headers'])) { + foreach ($this->_cache_info['headers'] as $h) + header($h); + } echo $_smarty_results; } error_reporting($_smarty_old_error_level) On Nov 8, 2007 2:52 AM, Hielke Hoeve <hielke.hoeve@...> wrote: > On 07/11/2007, Luke Baker <lukebaker@...> wrote: > > Attached is the changes I made against Smarty 2.6.18. I'd appreciate > > consideration for adding these changes to the Smarty core. > > There is no attachment, sorry. > > Hielke > > -- > 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 |
|
|
Re: Making Smarty's cache HTTP header aware--- Sebastian Mendel <lists@...> wrote:
> messju mohr schrieb: > > On Thu, Nov 08, 2007 at 09:30:12AM +0100, Sebastian Mendel wrote: > >> Hielke Hoeve schrieb: > >>> On 07/11/2007, Luke Baker <lukebaker@...> wrote: > >>>> Attached is the changes I made against Smarty 2.6.18. I'd appreciate > >>>> consideration for adding these changes to the Smarty core. > >>> There is no attachment, sorry. > >> i remember, in teh past patches that do add functionality for only a > >> specific PHP version where not accepted, did Smarty devs changed this > policy? > >> > >> (beside th fact that i did never understood why) > > > > Smarty-2.x requires php-4.0.6 or later. this requirement has never been > weakened. > > i was not talking about Smarty requirements, i was talking about features > working only with specific versions of PHP like the above mentioned I only can think of one exception, namely object iterator support which was added for PHP5 users; however, that was done without resorting to a PHP version compare, IIR. FWIW, I'm not against supporting this change either since it seems to have no impact on PHP4 users except for the version check (which I do dislike). I'd likely also support other PHP5 specific changes that can be done silently while also avoiding template syntax or parsing changes. That said, Luke, can you give more detail on why this is important? Thanks! __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awareOn Nov 8, 2007 2:06 PM, boots <jayboots@...> wrote:
[snip] > > That said, Luke, can you give more detail on why this is important? Thanks! Sure, I'd be happy to. The particular case that I ran into had to do with enabling client-side caching using the Cache-Control HTTP header. In my PHP code, I used something like the following: header("Cache-Control: max-age=21600, public"); That header call was in PHP code that only gets run when the smarty cache does not already exist. Therefore, when there is no cached file for this request, that header() gets called along with additional PHP code. However, any subsequent requests will be served from the Smarty cache, which returns only the content that I had sent previously, but not the headers. Without my patch, Smarty simply caches the content of the HTTP response. In most cases this is sufficient. However, the HTTP headers _and_ the content are what define an HTTP response, not just the content. My patch adds caching of the HTTP headers used in the response alongside the content. Thanks, Luke Baker -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Making Smarty's cache HTTP header awareI agree with the notion that the headers are as much a part of the response
as the HTML, itself. However; is it the entire response that Smarty is caching or just the HTML of the response-to-be? By placing these headers in the cached content, you're making that choice for the programmer. I do think allowing this would be useful, but it should be an optional behavior. Maybe a new Smarty method called "cacheHeaders()" or some such? - Dave (Rikaelus) ----- Original Message ----- From: "Luke Baker" <lukebaker@...> To: <smarty-dev@...> Sent: Thursday, November 08, 2007 12:26 PM Subject: Re: [SMARTY-DEV] Making Smarty's cache HTTP header aware > On Nov 8, 2007 2:06 PM, boots <jayboots@...> wrote: > [snip] >> >> That said, Luke, can you give more detail on why this is important? >> Thanks! > > Sure, I'd be happy to. The particular case that I ran into had to do > with enabling client-side caching using the Cache-Control HTTP > header. In my PHP code, I used something like the following: > header("Cache-Control: max-age=21600, public"); > > That header call was in PHP code that only gets run when the smarty > cache does not already exist. Therefore, when there is no cached file > for this request, that header() gets called along with additional PHP > code. However, any subsequent requests will be served from the Smarty > cache, which returns only the content that I had sent previously, but > not the headers. > > Without my patch, Smarty simply caches the content of the HTTP > response. In most cases this is sufficient. However, the HTTP > headers _and_ the content are what define an HTTP response, not just > the content. My patch adds caching of the HTTP headers used in the > response alongside the content. > > Thanks, > > Luke Baker > > -- > 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 |
|
|
Re: Making Smarty's cache HTTP header awareOn Nov 8, 2007 5:58 AM, Luke Baker <lukebaker@...> wrote:
> Hi, > > Currently, when Smarty caches content it has no knowledge of the HTTP > headers that the script served to the client. In the case where the > cache is cleared and the action sends special HTTP headers to the > client, those HTTP headers only get sent on the first response and > subsequent responses read from the cache and don't send the HTTP > headers. > > PHP5 provides the headers_list() function, so I've modified Smarty to > include that information in the cache meta-data and pass those headers > onto the client it when the headers are available in the meta-data. > This feature is PHP5 only, but will not break PHP4 code. > > Attached is the changes I made against Smarty 2.6.18. I'd appreciate > consideration for adding these changes to the Smarty core. > > Thanks, > > Luke Baker > Hello, I don't think we should HTTP header handling in the Smarty core, it is always easy to create a View class which handle all sort of HTTP header handling. Especially these functions didn't work with PHP4, which is bad. -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
| Free Forum Powered by Nabble | Forum Help |