From adc9a958afa5fb9f6f2dab4ae8abac1f932a7db4 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 3 Nov 2013 20:28:52 +0100 Subject: Préchargement et requêtes conditionnelles HTTP/1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Grosse amélioration des performances en utilisant le cache HTTP : - Implémentation de HTTP/1.1, c.a.d. If-Modified-Since, If-None-Match, If-Unmodified-Since, If-Match... avec la librairie http://alexandre.alapetite.fr/doc-alex/php-http-304/ - Support de HEAD (HTTP /1.0). - Préchargement de la page suivante (avec link next prefetch) dans le cas de pagination. - Et nouvelle possibilité de navigation pour les navigateurs qui supportent "next". - La date de dernier changement est pour l'instant primitive et correspond au dernier changement de la session PHP ou Configuration.array.php ou application.log ou touch.txt. - touch.txt est modifié a chaque requête UPDATE ou INSERT ou DELETE. --- lib/http-conditional.php | 207 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 lib/http-conditional.php (limited to 'lib/http-conditional.php') diff --git a/lib/http-conditional.php b/lib/http-conditional.php new file mode 100644 index 000000000..bd038aec3 --- /dev/null +++ b/lib/http-conditional.php @@ -0,0 +1,207 @@ +0, the document will be cashed and not revalidated against the server for this delay. + [Implied] $cachePrivacy=0: 0=private, 1=normal (public), 2=forced public. When public, it allows a cashed document ($cacheSeconds>0) to be shared by several users. + [Implied] $feedMode=false: Special RSS/ATOM feeds. When true, it sets $cachePrivacy to 0 (private), does not use the modification time of the script itself, and puts the date of the client's cache (or a old date from 1980) in the global variable $clientCacheDate. + [implied] $compression=false: Enable the compression and allows persistant connections (automatic detection of the capacities of the client). + [implied] $session=false: To be turned on when sessions are used. Checks if the data contained in $_SESSION has been modified during the last generation the document. + Returns: True if the connection can be closed (e.g.: the client has already the lastest version), false if the new content has to be send to the client. + + Typical use: + + + Version 1.6.2a, 2008-03-06, http://alexandre.alapetite.fr/doc-alex/php-http-304/ + + ------------------------------------------------------------------ + Written by Alexandre Alapetite, http://alexandre.alapetite.fr/cv/ + + Copyright 2004-2008, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR), + http://creativecommons.org/licenses/by-sa/2.0/fr/ + http://alexandre.alapetite.fr/divers/apropos/#by-sa + - Attribution. You must give the original author credit + - Share Alike. If you alter, transform, or build upon this work, + you may distribute the resulting work only under a license identical to this one + (Can be included in GPL/LGPL projects) + - The French law is authoritative + - Any of these conditions can be waived if you get permission from Alexandre Alapetite + - Please send to Alexandre Alapetite the modifications you make, + in order to improve this file for the benefit of everybody + + If you want to distribute this code, please do it as a link to: + http://alexandre.alapetite.fr/doc-alex/php-http-304/ +*/ + +//In RSS/ATOM feedMode, contains the date of the clients last update. +$clientCacheDate=0; //Global public variable because PHP4 does not allow conditional arguments by reference +$_sessionMode=false; //Global private variable + +function httpConditional($UnixTimeStamp,$cacheSeconds=0,$cachePrivacy=0,$feedMode=false,$compression=false,$session=false) +{//Credits: http://alexandre.alapetite.fr/doc-alex/php-http-304/ + //RFC2616 HTTP/1.1: http://www.w3.org/Protocols/rfc2616/rfc2616.html + //RFC1945 HTTP/1.0: http://www.w3.org/Protocols/rfc1945/rfc1945.txt + + if (headers_sent()) return false; + + if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptName=$_SERVER['SCRIPT_FILENAME']; + elseif (isset($_SERVER['PATH_TRANSLATED'])) $scriptName=$_SERVER['PATH_TRANSLATED']; + else return false; + + if ((!$feedMode)&&(($modifScript=filemtime($scriptName))>$UnixTimeStamp)) + $UnixTimeStamp=$modifScript; + $UnixTimeStamp=min($UnixTimeStamp,time()); + $is304=true; + $is412=false; + $nbCond=0; + + //rfc2616-sec3.html#sec3.3.1 + $dateLastModif=gmdate('D, d M Y H:i:s \G\M\T',$UnixTimeStamp); + $dateCacheClient='Thu, 10 Jan 1980 20:30:40 GMT'; + + //rfc2616-sec14.html#sec14.19 //='"0123456789abcdef0123456789abcdef"' + if (isset($_SERVER['QUERY_STRING'])) $myQuery='?'.$_SERVER['QUERY_STRING']; + else $myQuery=''; + if ($session&&isset($_SESSION)) + { + global $_sessionMode; + $_sessionMode=$session; + $myQuery.=print_r($_SESSION,true).session_name().'='.session_id(); + } + $etagServer='"'.md5($scriptName.$myQuery.'#'.$dateLastModif).'"'; + + if ((!$is412)&&isset($_SERVER['HTTP_IF_MATCH'])) + {//rfc2616-sec14.html#sec14.24 + $etagsClient=stripslashes($_SERVER['HTTP_IF_MATCH']); + $is412=(($etagClient!='*')&&(strpos($etagsClient,$etagServer)===false)); + } + if ($is304&&isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) + {//rfc2616-sec14.html#sec14.25 //rfc1945.txt + $nbCond++; + $dateCacheClient=$_SERVER['HTTP_IF_MODIFIED_SINCE']; + $p=strpos($dateCacheClient,';'); + if ($p!==false) + $dateCacheClient=substr($dateCacheClient,0,$p); + $is304=($dateCacheClient==$dateLastModif); + } + if ($is304&&isset($_SERVER['HTTP_IF_NONE_MATCH'])) + {//rfc2616-sec14.html#sec14.26 + $nbCond++; + $etagClient=stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); + $is304=(($etagClient==$etagServer)||($etagClient=='*')); + } + if ((!$is412)&&isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) + {//rfc2616-sec14.html#sec14.28 + $dateCacheClient=$_SERVER['HTTP_IF_UNMODIFIED_SINCE']; + $p=strpos($dateCacheClient,';'); + if ($p!==false) + $dateCacheClient=substr($dateCacheClient,0,$p); + $is412=($dateCacheClient!=$dateLastModif); + } + if ($feedMode) + {//Special RSS/ATOM + global $clientCacheDate; + $clientCacheDate=strtotime($dateCacheClient); + $cachePrivacy=0; + } + + if ($is412) + {//rfc2616-sec10.html#sec10.4.13 + header('HTTP/1.1 412 Precondition Failed'); + header('Cache-Control: private, max-age=0, must-revalidate'); + header('Content-Type: text/plain'); + echo "HTTP/1.1 Error 412 Precondition Failed: Precondition request failed positive evaluation\n"; + return true; + } + elseif ($is304&&($nbCond>0)) + {//rfc2616-sec10.html#sec10.3.5 + header('HTTP/1.0 304 Not Modified'); + header('Etag: '.$etagServer); + if ($feedMode) header('Connection: close'); //Comment this line under IIS + return true; + } + else + {//rfc2616-sec10.html#sec10.2.1 + //rfc2616-sec14.html#sec14.3 + if ($compression) ob_start('_httpConditionalCallBack'); //Will check HTTP_ACCEPT_ENCODING + //header('HTTP/1.0 200 OK'); + if ($cacheSeconds<0) + { + $cache='private, no-cache, no-store, must-revalidate'; + header('Pragma: no-cache'); + } + else + { + if ($cacheSeconds==0) $cache='private, must-revalidate, '; + elseif ($cachePrivacy==0) $cache='private, '; + elseif ($cachePrivacy==2) $cache='public, '; + else $cache=''; + $cache.='max-age='.floor($cacheSeconds); + } + //header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+$cacheSeconds)); //HTTP/1.0 //rfc2616-sec14.html#sec14.21 + header('Cache-Control: '.$cache); //rfc2616-sec14.html#sec14.9 + header('Last-Modified: '.$dateLastModif); + header('Etag: '.$etagServer); + if ($feedMode) header('Connection: close'); //rfc2616-sec14.html#sec14.10 //Comment this line under IIS + return $_SERVER['REQUEST_METHOD']=='HEAD'; //rfc2616-sec9.html#sec9.4 + } +} + +function _httpConditionalCallBack($buffer,$mode=5) +{//Private function automatically called at the end of the script when compression is enabled + //rfc2616-sec14.html#sec14.11 + //You can adjust the level of compression with zlib.output_compression_level in php.ini + if (extension_loaded('zlib')&&(!ini_get('zlib.output_compression'))) + { + $buffer2=ob_gzhandler($buffer,$mode); //Will check HTTP_ACCEPT_ENCODING and put correct headers such as Vary //rfc2616-sec14.html#sec14.44 + if (strlen($buffer2)>1) //When ob_gzhandler succeeded + $buffer=$buffer2; + } + header('Content-Length: '.strlen($buffer)); //Allows persistant connections //rfc2616-sec14.html#sec14.13 + return $buffer; +} + +function httpConditionalRefresh($UnixTimeStamp) +{//Update HTTP headers if the content has just been modified by the client's request + //See an example on http://alexandre.alapetite.fr/doc-alex/compteur/ + if (headers_sent()) return false; + + if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptName=$_SERVER['SCRIPT_FILENAME']; + elseif (isset($_SERVER['PATH_TRANSLATED'])) $scriptName=$_SERVER['PATH_TRANSLATED']; + else return false; + + $dateLastModif=gmdate('D, d M Y H:i:s \G\M\T',$UnixTimeStamp); + + if (isset($_SERVER['QUERY_STRING'])) $myQuery='?'.$_SERVER['QUERY_STRING']; + else $myQuery=''; + global $_sessionMode; + if ($_sessionMode&&isset($_SESSION)) + $myQuery.=print_r($_SESSION,true).session_name().'='.session_id(); + $etagServer='"'.md5($scriptName.$myQuery.'#'.$dateLastModif).'"'; + + header('Last-Modified: '.$dateLastModif); + header('Etag: '.$etagServer); +} -- cgit v1.2.3 From 665d22be76db6ea58ee88bf29674fd37b36f5e68 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 3 Nov 2013 22:29:15 +0100 Subject: Mise à jour de la librairie http-conditional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout d'un entête Expires qui ne devrait pas être nécessaire d'après la spécification mais qui semble aider certains navigateurs --- lib/http-conditional.php | 273 ++++++++++++++++++++++++----------------------- 1 file changed, 139 insertions(+), 134 deletions(-) (limited to 'lib/http-conditional.php') diff --git a/lib/http-conditional.php b/lib/http-conditional.php index bd038aec3..1cf37725d 100644 --- a/lib/http-conditional.php +++ b/lib/http-conditional.php @@ -35,12 +35,12 @@ ... //Rest of the script, just as you would do normally. ?> - Version 1.6.2a, 2008-03-06, http://alexandre.alapetite.fr/doc-alex/php-http-304/ + Version 1.7 beta, 2013-11-03, http://alexandre.alapetite.fr/doc-alex/php-http-304/ ------------------------------------------------------------------ Written by Alexandre Alapetite, http://alexandre.alapetite.fr/cv/ - Copyright 2004-2008, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR), + Copyright 2004-2013, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR), http://creativecommons.org/licenses/by-sa/2.0/fr/ http://alexandre.alapetite.fr/divers/apropos/#by-sa - Attribution. You must give the original author credit @@ -57,151 +57,156 @@ */ //In RSS/ATOM feedMode, contains the date of the clients last update. -$clientCacheDate=0; //Global public variable because PHP4 does not allow conditional arguments by reference -$_sessionMode=false; //Global private variable +$clientCacheDate=0; //Global public variable because PHP4 does not allow conditional arguments by reference +$_sessionMode=false; //Global private variable function httpConditional($UnixTimeStamp,$cacheSeconds=0,$cachePrivacy=0,$feedMode=false,$compression=false,$session=false) {//Credits: http://alexandre.alapetite.fr/doc-alex/php-http-304/ - //RFC2616 HTTP/1.1: http://www.w3.org/Protocols/rfc2616/rfc2616.html - //RFC1945 HTTP/1.0: http://www.w3.org/Protocols/rfc1945/rfc1945.txt - - if (headers_sent()) return false; - - if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptName=$_SERVER['SCRIPT_FILENAME']; - elseif (isset($_SERVER['PATH_TRANSLATED'])) $scriptName=$_SERVER['PATH_TRANSLATED']; - else return false; - - if ((!$feedMode)&&(($modifScript=filemtime($scriptName))>$UnixTimeStamp)) - $UnixTimeStamp=$modifScript; - $UnixTimeStamp=min($UnixTimeStamp,time()); - $is304=true; - $is412=false; - $nbCond=0; - - //rfc2616-sec3.html#sec3.3.1 - $dateLastModif=gmdate('D, d M Y H:i:s \G\M\T',$UnixTimeStamp); - $dateCacheClient='Thu, 10 Jan 1980 20:30:40 GMT'; - - //rfc2616-sec14.html#sec14.19 //='"0123456789abcdef0123456789abcdef"' - if (isset($_SERVER['QUERY_STRING'])) $myQuery='?'.$_SERVER['QUERY_STRING']; - else $myQuery=''; - if ($session&&isset($_SESSION)) - { - global $_sessionMode; - $_sessionMode=$session; - $myQuery.=print_r($_SESSION,true).session_name().'='.session_id(); - } - $etagServer='"'.md5($scriptName.$myQuery.'#'.$dateLastModif).'"'; - - if ((!$is412)&&isset($_SERVER['HTTP_IF_MATCH'])) - {//rfc2616-sec14.html#sec14.24 - $etagsClient=stripslashes($_SERVER['HTTP_IF_MATCH']); - $is412=(($etagClient!='*')&&(strpos($etagsClient,$etagServer)===false)); - } - if ($is304&&isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) - {//rfc2616-sec14.html#sec14.25 //rfc1945.txt - $nbCond++; - $dateCacheClient=$_SERVER['HTTP_IF_MODIFIED_SINCE']; - $p=strpos($dateCacheClient,';'); - if ($p!==false) - $dateCacheClient=substr($dateCacheClient,0,$p); - $is304=($dateCacheClient==$dateLastModif); - } - if ($is304&&isset($_SERVER['HTTP_IF_NONE_MATCH'])) - {//rfc2616-sec14.html#sec14.26 - $nbCond++; - $etagClient=stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); - $is304=(($etagClient==$etagServer)||($etagClient=='*')); - } - if ((!$is412)&&isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) - {//rfc2616-sec14.html#sec14.28 - $dateCacheClient=$_SERVER['HTTP_IF_UNMODIFIED_SINCE']; - $p=strpos($dateCacheClient,';'); - if ($p!==false) - $dateCacheClient=substr($dateCacheClient,0,$p); - $is412=($dateCacheClient!=$dateLastModif); - } - if ($feedMode) - {//Special RSS/ATOM - global $clientCacheDate; - $clientCacheDate=strtotime($dateCacheClient); - $cachePrivacy=0; - } - - if ($is412) - {//rfc2616-sec10.html#sec10.4.13 - header('HTTP/1.1 412 Precondition Failed'); - header('Cache-Control: private, max-age=0, must-revalidate'); - header('Content-Type: text/plain'); - echo "HTTP/1.1 Error 412 Precondition Failed: Precondition request failed positive evaluation\n"; - return true; - } - elseif ($is304&&($nbCond>0)) - {//rfc2616-sec10.html#sec10.3.5 - header('HTTP/1.0 304 Not Modified'); - header('Etag: '.$etagServer); - if ($feedMode) header('Connection: close'); //Comment this line under IIS - return true; - } - else - {//rfc2616-sec10.html#sec10.2.1 - //rfc2616-sec14.html#sec14.3 - if ($compression) ob_start('_httpConditionalCallBack'); //Will check HTTP_ACCEPT_ENCODING - //header('HTTP/1.0 200 OK'); - if ($cacheSeconds<0) - { - $cache='private, no-cache, no-store, must-revalidate'; - header('Pragma: no-cache'); - } - else - { - if ($cacheSeconds==0) $cache='private, must-revalidate, '; - elseif ($cachePrivacy==0) $cache='private, '; - elseif ($cachePrivacy==2) $cache='public, '; - else $cache=''; - $cache.='max-age='.floor($cacheSeconds); - } - //header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+$cacheSeconds)); //HTTP/1.0 //rfc2616-sec14.html#sec14.21 - header('Cache-Control: '.$cache); //rfc2616-sec14.html#sec14.9 - header('Last-Modified: '.$dateLastModif); - header('Etag: '.$etagServer); - if ($feedMode) header('Connection: close'); //rfc2616-sec14.html#sec14.10 //Comment this line under IIS - return $_SERVER['REQUEST_METHOD']=='HEAD'; //rfc2616-sec9.html#sec9.4 - } + //RFC2616 HTTP/1.1: http://www.w3.org/Protocols/rfc2616/rfc2616.html + //RFC1945 HTTP/1.0: http://www.w3.org/Protocols/rfc1945/rfc1945.txt + + if (headers_sent()) return false; + + if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptName=$_SERVER['SCRIPT_FILENAME']; + elseif (isset($_SERVER['PATH_TRANSLATED'])) $scriptName=$_SERVER['PATH_TRANSLATED']; + else return false; + + if ((!$feedMode)&&(($modifScript=filemtime($scriptName))>$UnixTimeStamp)) + $UnixTimeStamp=$modifScript; + $UnixTimeStamp=min($UnixTimeStamp,time()); + $is304=true; + $is412=false; + $nbCond=0; + + //rfc2616-sec3.html#sec3.3.1 + $dateLastModif=gmdate('D, d M Y H:i:s \G\M\T',$UnixTimeStamp); + $dateCacheClient='Thu, 10 Jan 1980 20:30:40 GMT'; + + //rfc2616-sec14.html#sec14.19 //='"0123456789abcdef0123456789abcdef"' + if (isset($_SERVER['QUERY_STRING'])) $myQuery='?'.$_SERVER['QUERY_STRING']; + else $myQuery=''; + if ($session&&isset($_SESSION)) + { + global $_sessionMode; + $_sessionMode=$session; + $myQuery.=print_r($_SESSION,true).session_name().'='.session_id(); + } + $etagServer='"'.md5($scriptName.$myQuery.'#'.$dateLastModif).'"'; + + if ((!$is412)&&isset($_SERVER['HTTP_IF_MATCH'])) + {//rfc2616-sec14.html#sec14.24 + $etagsClient=stripslashes($_SERVER['HTTP_IF_MATCH']); + $is412=(($etagClient!=='*')&&(strpos($etagsClient,$etagServer)===false)); + } + if ($is304&&isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) + {//rfc2616-sec14.html#sec14.25 //rfc1945.txt + $nbCond++; + $dateCacheClient=$_SERVER['HTTP_IF_MODIFIED_SINCE']; + $p=strpos($dateCacheClient,';'); + if ($p!==false) + $dateCacheClient=substr($dateCacheClient,0,$p); + $is304=($dateCacheClient==$dateLastModif); + } + if ($is304&&isset($_SERVER['HTTP_IF_NONE_MATCH'])) + {//rfc2616-sec14.html#sec14.26 + $nbCond++; + $etagClient=stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); + $is304=(($etagClient===$etagServer)||($etagClient==='*')); + } + if ((!$is412)&&isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) + {//rfc2616-sec14.html#sec14.28 + $dateCacheClient=$_SERVER['HTTP_IF_UNMODIFIED_SINCE']; + $p=strpos($dateCacheClient,';'); + if ($p!==false) + $dateCacheClient=substr($dateCacheClient,0,$p); + $is412=($dateCacheClient!==$dateLastModif); + } + if ($feedMode) + {//Special RSS/ATOM + global $clientCacheDate; + $clientCacheDate=strtotime($dateCacheClient); + $cachePrivacy=0; + } + + if ($is412) + {//rfc2616-sec10.html#sec10.4.13 + header('HTTP/1.1 412 Precondition Failed'); + header('Cache-Control: private, max-age=0, must-revalidate'); + header('Content-Type: text/plain'); + echo "HTTP/1.1 Error 412 Precondition Failed: Precondition request failed positive evaluation\n"; + return true; + } + elseif ($is304&&($nbCond>0)) + {//rfc2616-sec10.html#sec10.3.5 + header('HTTP/1.0 304 Not Modified'); + header('Etag: '.$etagServer); + if ($feedMode) header('Connection: close'); //Comment this line under IIS + return true; + } + else + {//rfc2616-sec10.html#sec10.2.1 + //rfc2616-sec14.html#sec14.3 + if ($compression) ob_start('_httpConditionalCallBack'); //Will check HTTP_ACCEPT_ENCODING + //header('HTTP/1.0 200 OK'); + if ($cacheSeconds<0) + { + $cache='private, no-cache, no-store, must-revalidate'; + header('Expires: 0'); + header('Pragma: no-cache'); + } + else + { + if ($cacheSeconds===0) + { + $cache='private, must-revalidate, '; + header('Expires: 0'); + } + elseif ($cachePrivacy===0) $cache='private, '; + elseif ($cachePrivacy===2) $cache='public, '; + else $cache=''; + $cache.='max-age='.floor($cacheSeconds); + } + //header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+$cacheSeconds)); //HTTP/1.0 //rfc2616-sec14.html#sec14.21 + header('Cache-Control: '.$cache); //rfc2616-sec14.html#sec14.9 + header('Last-Modified: '.$dateLastModif); + header('Etag: '.$etagServer); + if ($feedMode) header('Connection: close'); //rfc2616-sec14.html#sec14.10 //Comment this line under IIS + return $_SERVER['REQUEST_METHOD']==='HEAD'; //rfc2616-sec9.html#sec9.4 + } } function _httpConditionalCallBack($buffer,$mode=5) {//Private function automatically called at the end of the script when compression is enabled - //rfc2616-sec14.html#sec14.11 - //You can adjust the level of compression with zlib.output_compression_level in php.ini - if (extension_loaded('zlib')&&(!ini_get('zlib.output_compression'))) - { - $buffer2=ob_gzhandler($buffer,$mode); //Will check HTTP_ACCEPT_ENCODING and put correct headers such as Vary //rfc2616-sec14.html#sec14.44 - if (strlen($buffer2)>1) //When ob_gzhandler succeeded - $buffer=$buffer2; - } - header('Content-Length: '.strlen($buffer)); //Allows persistant connections //rfc2616-sec14.html#sec14.13 - return $buffer; + //rfc2616-sec14.html#sec14.11 + //You can adjust the level of compression with zlib.output_compression_level in php.ini + if (extension_loaded('zlib')&&(!ini_get('zlib.output_compression'))) + { + $buffer2=ob_gzhandler($buffer,$mode); //Will check HTTP_ACCEPT_ENCODING and put correct headers such as Vary //rfc2616-sec14.html#sec14.44 + if (strlen($buffer2)>1) //When ob_gzhandler succeeded + $buffer=$buffer2; + } + header('Content-Length: '.strlen($buffer)); //Allows persistant connections //rfc2616-sec14.html#sec14.13 + return $buffer; } function httpConditionalRefresh($UnixTimeStamp) {//Update HTTP headers if the content has just been modified by the client's request - //See an example on http://alexandre.alapetite.fr/doc-alex/compteur/ - if (headers_sent()) return false; + //See an example on http://alexandre.alapetite.fr/doc-alex/compteur/ + if (headers_sent()) return false; - if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptName=$_SERVER['SCRIPT_FILENAME']; - elseif (isset($_SERVER['PATH_TRANSLATED'])) $scriptName=$_SERVER['PATH_TRANSLATED']; - else return false; + if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptName=$_SERVER['SCRIPT_FILENAME']; + elseif (isset($_SERVER['PATH_TRANSLATED'])) $scriptName=$_SERVER['PATH_TRANSLATED']; + else return false; - $dateLastModif=gmdate('D, d M Y H:i:s \G\M\T',$UnixTimeStamp); + $dateLastModif=gmdate('D, d M Y H:i:s \G\M\T',$UnixTimeStamp); - if (isset($_SERVER['QUERY_STRING'])) $myQuery='?'.$_SERVER['QUERY_STRING']; - else $myQuery=''; - global $_sessionMode; - if ($_sessionMode&&isset($_SESSION)) - $myQuery.=print_r($_SESSION,true).session_name().'='.session_id(); - $etagServer='"'.md5($scriptName.$myQuery.'#'.$dateLastModif).'"'; + if (isset($_SERVER['QUERY_STRING'])) $myQuery='?'.$_SERVER['QUERY_STRING']; + else $myQuery=''; + global $_sessionMode; + if ($_sessionMode&&isset($_SESSION)) + $myQuery.=print_r($_SESSION,true).session_name().'='.session_id(); + $etagServer='"'.md5($scriptName.$myQuery.'#'.$dateLastModif).'"'; - header('Last-Modified: '.$dateLastModif); - header('Etag: '.$etagServer); + header('Last-Modified: '.$dateLastModif); + header('Etag: '.$etagServer); } -- cgit v1.2.3 From 4a999fb6286bafcd070a1ebe53ceb5effacc8b59 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 4 Nov 2013 20:23:46 +0100 Subject: Améliorations chargement JS async MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En particulier pour global_view.js. Suppression d'une requête avortée dans Chrome. --- lib/http-conditional.php | 4 ++-- public/scripts/global_view.js | 13 ++++++++++--- public/scripts/main.js | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'lib/http-conditional.php') diff --git a/lib/http-conditional.php b/lib/http-conditional.php index 1cf37725d..6684fd6ac 100644 --- a/lib/http-conditional.php +++ b/lib/http-conditional.php @@ -151,7 +151,7 @@ function httpConditional($UnixTimeStamp,$cacheSeconds=0,$cachePrivacy=0,$feedMod if ($cacheSeconds<0) { $cache='private, no-cache, no-store, must-revalidate'; - header('Expires: 0'); + //header('Expires: 0'); header('Pragma: no-cache'); } else @@ -159,7 +159,7 @@ function httpConditional($UnixTimeStamp,$cacheSeconds=0,$cachePrivacy=0,$feedMod if ($cacheSeconds===0) { $cache='private, must-revalidate, '; - header('Expires: 0'); + //header('Expires: 0'); } elseif ($cachePrivacy===0) $cache='private, '; elseif ($cachePrivacy===2) $cache='public, '; diff --git a/public/scripts/global_view.js b/public/scripts/global_view.js index 7c2def775..2c95bdfb7 100644 --- a/public/scripts/global_view.js +++ b/public/scripts/global_view.js @@ -52,12 +52,19 @@ function init_global_view() { init_stream_delegates($("#panel")); } -if (document.readyState && document.readyState !== 'loading') { +function init_all_global_view() { + if (!(window.$ && window.init_stream_delegates)) { + window.setTimeout(init_all_global_view, 50); //Wait for all js to be loaded + return; + } init_global_view(); init_close_panel(); +} + +if (document.readyState && document.readyState !== 'loading') { + init_all_global_view(); } else if (document.addEventListener) { document.addEventListener('DOMContentLoaded', function () { - init_global_view(); - init_close_panel(); + init_all_global_view(); }, false); } diff --git a/public/scripts/main.js b/public/scripts/main.js index 325aa03ca..f4bffcca8 100644 --- a/public/scripts/main.js +++ b/public/scripts/main.js @@ -492,6 +492,7 @@ function init_load_more() { url_load_more = $next_link.attr("href"); var $prefetch = $('#prefetch'); if ($prefetch.attr('href') !== url_load_more) { + $prefetch.attr('rel', 'next'); //Remove prefetch $.ajax({url: url_load_more, ifModified: true }); //TODO: Try to find a less agressive solution $prefetch.attr('href', url_load_more); } @@ -504,7 +505,7 @@ function init_load_more() { // function init_all() { - if (!(window.$ && window.shortcut && ((!full_lazyload) || $.fn.lazyload))) { + if (!(window.$ && window.shortcut && window.shortcuts && ((!full_lazyload) || $.fn.lazyload))) { if (window.console) { console.log('Waiting for JS…'); } -- cgit v1.2.3 From 56b269cef6bc54fa8d8fc69ff0f0e8b2ffb36afb Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 2 Dec 2013 20:12:55 +0100 Subject: PHP : suppression autres alertes Voir https://github.com/marienfressinaud/FreshRSS/issues/310 --- app/layout/nav_menu.phtml | 2 +- app/models/Entry.php | 2 +- app/models/Feed.php | 2 +- lib/http-conditional.php | 4 ++-- public/install.php | 1 + 5 files changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/http-conditional.php') diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 4b4945108..c71497ced 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -70,7 +70,7 @@
  • diff --git a/app/models/Entry.php b/app/models/Entry.php index 196823f67..899e98b00 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -137,7 +137,7 @@ class Entry extends Model { public function isDay ($day) { $date = $this->dateAdded(true); - $today = strtotime('today'); + $today = @strtotime('today'); $yesterday = $today - 86400; if ($day === Days::TODAY && diff --git a/app/models/Feed.php b/app/models/Feed.php index c1d0379a9..555759c9a 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -265,7 +265,7 @@ class Feed extends Model { $title = html_only_entity_decode (strip_tags ($item->get_title ())); $author = $item->get_author (); $link = $item->get_permalink (); - $date = strtotime ($item->get_date ()); + $date = @strtotime ($item->get_date ()); // gestion des tags (catégorie == tag) $tags_tmp = $item->get_categories (); diff --git a/lib/http-conditional.php b/lib/http-conditional.php index 6684fd6ac..59fbef41f 100644 --- a/lib/http-conditional.php +++ b/lib/http-conditional.php @@ -35,7 +35,7 @@ ... //Rest of the script, just as you would do normally. ?> - Version 1.7 beta, 2013-11-03, http://alexandre.alapetite.fr/doc-alex/php-http-304/ + Version 1.7 beta, 2013-12-02, http://alexandre.alapetite.fr/doc-alex/php-http-304/ ------------------------------------------------------------------ Written by Alexandre Alapetite, http://alexandre.alapetite.fr/cv/ @@ -124,7 +124,7 @@ function httpConditional($UnixTimeStamp,$cacheSeconds=0,$cachePrivacy=0,$feedMod if ($feedMode) {//Special RSS/ATOM global $clientCacheDate; - $clientCacheDate=strtotime($dateCacheClient); + $clientCacheDate=@strtotime($dateCacheClient); $cachePrivacy=0; } diff --git a/public/install.php b/public/install.php index 577714764..6765d8cd1 100644 --- a/public/install.php +++ b/public/install.php @@ -228,6 +228,7 @@ function saveStep3 () { $_SESSION['bd_error'] = true; } } + invalidateHttpCache(); } function deleteInstall () { $res = unlink (PUBLIC_PATH . '/install.php'); -- cgit v1.2.3