I was wondering if there is any way to check if a website has enabled Cache-Control
for a file type and its expiry time
example for
http://foo.com/foo.css
how can i know if Cache-Control is enabled for it and whats is the expiry time set for it
user2533777
问问题
1595 次
2 回答
0
Try this:
$ch = curl_init();
$url = 'http://stackoverflow.com/questions/19320848/how-to-check-if-a-site-has-enabled-cache-control-for-a-file-type';
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $ch, CURLOPT_HEADER, true );
curl_setopt( $ch, CURLOPT_NOBODY, true );
$res = explode( "\n", curl_exec( $ch ) );
foreach( $res as $line ) {
if( strpos( $line, 'Expires:' ) !== false ) {
$line = explode( ':', $line );
array_shift( $line );
echo 'Page expires on - ' . trim( implode( ':', $line ) );
}
}
curl_close( $ch );
Hope this helps.
于 2013-10-11T14:48:11.540 回答
0
You can try this:
<?php
$temp = curl_init();
curl_setopt( $temp, CURLOPT_URL, 'http://foo.com/foo.css' );
curl_setopt( $temp, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $temp, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $temp, CURLOPT_HEADER, true );
curl_setopt( $temp, CURLOPT_NOBODY, true );
echo curl_exec( $temp );
curl_close( $temp );
?>
This will return an output like This:
HTTP/1.1 200 OK Server: Date: Current Date GMT Content-Type: text/css Content-Length: 2713 Connection: keep-alive Vary: Accept-Encoding Last-Modified: Date of file creation Accept-Ranges: bytes Cache-Control: max-age=expiry time in sec set for it Expires: Expiry Date GMT
于 2013-10-21T06:51:00.873 回答