Mailing List Archive

caching php
Hi,

I installed varnish (from trunk) lauched with :
/usr/local/varnish/sbin/varnishd -a '0.0.0.0:80' -b'127.0.0.1:8080' -T
127.0.0.1:1664 -sfile,/tmp/varnish,1g -t 1200

But I have a problem with php scripts being cached, which is really annoying.

Normally a http response containing ETag or Last-Modified can be
cached but other should not !
Is it a wanted behavior of varnish not to respect this ? is it a bug ?

Any help would be welcome to help me not cache php.

Thanks
caching php [ In reply to ]
Cedric Tabary wrote:

> I installed varnish (from trunk) lauched with :
> /usr/local/varnish/sbin/varnishd -a '0.0.0.0:80' -b'127.0.0.1:8080' -T
> 127.0.0.1:1664 -sfile,/tmp/varnish,1g -t 1200
>
> But I have a problem with php scripts being cached, which is really annoying.

You might want to loose the minimum caching time parameter (-t 1200).


/Anton
caching php [ In reply to ]
On 11/10/2006 11:03, Anton Stonor wrote:
> Cedric Tabary wrote:
>
> >I installed varnish (from trunk) lauched with :
> >/usr/local/varnish/sbin/varnishd -a '0.0.0.0:80' -b'127.0.0.1:8080' -T
> >127.0.0.1:1664 -sfile,/tmp/varnish,1g -t 1200
> >
> >But I have a problem with php scripts being cached, which is really
> >annoying.
>
> You might want to loose the minimum caching time parameter (-t 1200).

I removed the -t 1200, but my php is still cached !

(I also tried -t 0 but nothing is cached then)

C?dric
caching php [ In reply to ]
Cedric Tabary wrote:

> I removed the -t 1200, but my php is still cached !

Well, maybe the HTTP headers from the backend invites Varnish to cache.
Or there _could_ be a bug in Varnish.

Could you post an example HTTP header of an object you expect Varnish
not to cache?

http://www.web-caching.com/ is a great resource about HTTP headers and
caching, btw.

/Anton
caching php [ In reply to ]
On 11/10/2006 16:17, Anton Stonor wrote:
> Cedric Tabary wrote:
>
> >I removed the -t 1200, but my php is still cached !
>
> Well, maybe the HTTP headers from the backend invites Varnish to cache.
> Or there _could_ be a bug in Varnish.
>
> Could you post an example HTTP header of an object you expect Varnish
> not to cache?

I have a simple php script as example :
time.php:
<?
echo time();
?>

Here are the headers from the backend directly :
root at php10:~/varnish-cache% HEAD http://127.0.0.1:8080/time.php
200 OK
Connection: close
Date: Wed, 11 Oct 2006 14:20:08 GMT
Server: Apache/1.3.34 (Unix) PHP/4.4.2 mod_ssl/2.8.25 OpenSSL/0.9.7g
Content-Type: text/html; charset=iso-8859-1
Client-Date: Wed, 11 Oct 2006 14:20:08 GMT
Client-Peer: 127.0.0.1:8080
Client-Response-Num: 1
X-Powered-By: PHP/4.4.2

And the headers through varnish :
root at php10:~/varnish-cache% HEAD http://127.0.0.1/time.php
200 OK
Connection: close
Date: Wed, 11 Oct 2006 14:22:42 GMT
Via: 1.1 varnish
Age: 5
Server: Apache/1.3.34 (Unix) PHP/4.4.2 mod_ssl/2.8.25 OpenSSL/0.9.7g
Content-Length: 10
Content-Type: text/html; charset=iso-8859-1
Client-Date: Wed, 11 Oct 2006 14:22:47 GMT
Client-Peer: 127.0.0.1:80
Client-Response-Num: 1
X-Powered-By: PHP/4.4.2
X-Varnish: 1281745475 1281745470


I also managed to get a log of varnish inserting the php script in cache :

12 SessionOpen c 127.0.0.1 36672
12 ReqStart c 127.0.0.1 36672 1281745566
12 RxRequest c HEAD
12 RxURL c /time.php
12 RxProtocol c HTTP/1.1
12 RxHeader c Connection: close
12 RxHeader c Host: 127.0.0.1
12 RxHeader c User-Agent: lwp-request/2.06
12 VCL_call c recv
12 VCL_return c lookup
12 VCL_call c miss
12 VCL_return c fetch
15 BackendOpen b default 127.0.0.1 24543 127.0.0.1 8080
15 BackendXID b 1281745566
12 Backend c 15 default
15 TxRequest b GET
15 TxURL b /time.php
15 TxProtocol b HTTP/1.1
15 TxHeader b Host: 127.0.0.1
15 TxHeader b User-Agent: lwp-request/2.06
15 TxHeader b X-Varnish: 1281745566
15 TxHeader b X-Forwarded-for: 127.0.0.1
15 RxProtocol b HTTP/1.1
15 RxStatus b 200
15 RxResponse b OK
15 RxHeader b Date: Wed, 11 Oct 2006 14:29:19 GMT
15 RxHeader b Server: Apache/1.3.34 (Unix) PHP/4.4.2
mod_ssl/2.8.25 OpenSSL/0.9.7g
15 RxHeader b X-Powered-By: PHP/4.4.2
15 RxHeader b Connection: close
15 RxHeader b Transfer-Encoding: chunked
15 RxHeader b Content-Type: text/html; charset=iso-8859-1
12 TTL c 1281745566 RFC 120 1160576959 1160576959 0 0 0
12 VCL_call c fetch
12 VCL_return c insert
12 ObjProtocol c HTTP/1.1
12 ObjStatus c 200
12 ObjResponse c OK
12 ObjHeader c Date: Wed, 11 Oct 2006 14:29:19 GMT
12 ObjHeader c Server: Apache/1.3.34 (Unix) PHP/4.4.2
mod_ssl/2.8.25 OpenSSL/0.9.7g
12 ObjHeader c X-Powered-By: PHP/4.4.2
12 ObjHeader c Content-Type: text/html; charset=iso-8859-1
12 ObjHeader c Content-Length: 10
15 BackendClose b default
12 Length c 10
12 TxProtocol c HTTP/1.1
12 TxStatus c 200
12 TxResponse c OK
12 TxHeader c Date: Wed, 11 Oct 2006 14:29:19 GMT
12 TxHeader c Server: Apache/1.3.34 (Unix) PHP/4.4.2
mod_ssl/2.8.25 OpenSSL/0.9.7g
12 TxHeader c X-Powered-By: PHP/4.4.2
12 TxHeader c Content-Type: text/html; charset=iso-8859-1
12 TxHeader c Content-Length: 10
12 TxHeader c X-Varnish: 1281745566
12 TxHeader c Age: 0
12 TxHeader c Via: 1.1 varnish
12 TxHeader c Connection: close
12 ReqEnd c 1281745566 1160576959.257762000
1160576959.258505000 0.002817000 0.000721000 0.000022000
0 StatAddr 127.0.0.1 0 397 11 11 0 0 3 3218 0
12 SessionClose c Connection: close
12 StatSess c 127.0.0.1 36672 0 1 1 0 0 1 284 0


C?dric
caching php [ In reply to ]
In message <20061011142915.GC34666 at efrei.fr>, Cedric Tabary writes:
>On 11/10/2006 16:17, Anton Stonor wrote:
>> Cedric Tabary wrote:
>>
>> >I removed the -t 1200, but my php is still cached !
>>
>> Well, maybe the HTTP headers from the backend invites Varnish to cache.
>> Or there _could_ be a bug in Varnish.
>>
>> Could you post an example HTTP header of an object you expect Varnish
>> not to cache?

Varnish has a "default TTL" which you can specify on the command line
or modify from the CLI.

Absent any instruction from the backend, Varnish will cache objects
that long.

Default is 2 minutes.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
caching php [ In reply to ]
On 11/10/2006 14:37, Poul-Henning Kamp wrote:
> In message <20061011142915.GC34666 at efrei.fr>, Cedric Tabary writes:
> >On 11/10/2006 16:17, Anton Stonor wrote:
> >> Cedric Tabary wrote:
> >>
> >> >I removed the -t 1200, but my php is still cached !
> >>
> >> Well, maybe the HTTP headers from the backend invites Varnish to cache.
> >> Or there _could_ be a bug in Varnish.
> >>
> >> Could you post an example HTTP header of an object you expect Varnish
> >> not to cache?
>
> Varnish has a "default TTL" which you can specify on the command line
> or modify from the CLI.
>
> Absent any instruction from the backend, Varnish will cache objects
> that long.

Ok so I have to put -t 0 and specify a Cache-Control with mod_expires
on static content ?

And if I put a Cache-Control header in a specific php script I
can also make it cacheable ?

this sounds good to me :)
I will try this...

C?dric
caching php [ In reply to ]
In message <20061011145129.GD34666 at efrei.fr>, Cedric Tabary writes:

>> Varnish has a "default TTL" which you can specify on the command line
>> or modify from the CLI.
>>
>> Absent any instruction from the backend, Varnish will cache objects
>> that long.
>
>Ok so I have to put -t 0 and specify a Cache-Control with mod_expires
>on static content ?

Yes.

>And if I put a Cache-Control header in a specific php script I
>can also make it cacheable ?

Yes.

>this sounds good to me :)

I hope so :-)

The 120 second default is sort of a stab at a good default
"anti-slashdotting" setting, but obviously it's open for discussion
if ot proves to be a Bad Thing.


--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.