cvs: presentations /slides/intro yql.xml

From: Date: Tue, 24 Feb 2009 17:42:15 +0000
Subject: cvs: presentations /slides/intro yql.xml
Groups: php.pres 
Request: Send a blank email to pres+get-1538@lists.php.net to get a copy of this message
rasmus Tue Feb 24 17:42:15 2009 UTC Modified files: /presentations/slides/intro yql.xml Log: Better cache function http://cvs.php.net/viewvc.cgi/presentations/slides/intro/yql.xml?r1=1.1&r2=1.2&diff_format=u Index: presentations/slides/intro/yql.xml diff -u presentations/slides/intro/yql.xml:1.1 presentations/slides/intro/yql.xml:1.2 --- presentations/slides/intro/yql.xml:1.1 Tue Feb 17 22:41:45 2009 +++ presentations/slides/intro/yql.xml Tue Feb 24 17:42:15 2009 @@ -31,11 +31,13 @@ ?>]]></example> <example title="Add a Cache" result="1" fontsize="1.4em"><![CDATA[<?php +define('MINSZ',10); function cache($url) { $tmp = '/tmp/'.md5($url); - if(!$fe=file_exists($tmp) || $fe && filemtime($tmp) < (time()-7200)) { - if($fe) touch($tmp); - $stream = fopen($url,'r'); + $st = stat($tmp); + if(!$st || $st && ($st['size']<MINSZ || $st['mtime']<(time()-7200))) { + if($st && $st['size']>=MINSZ) touch($tmp); // Keep re-using entry + $stream = fopen($url,'r'); // until new is ready $tmpf = tempnam('/tmp','YWS'); file_put_contents($tmpf, $stream); fclose($stream);

« previous php.pres (#1538) next »