svn: /web/php/trunk/ ws.php

From: Date: Sun, 17 Jul 2011 04:17:46 +0000
Subject: svn: /web/php/trunk/ ws.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-11674@lists.php.net to get a copy of this message
rasmus Sun, 17 Jul 2011 04:17:46 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=313308 Log: Log if we returned a cached result Changed paths: U web/php/trunk/ws.php Modified: web/php/trunk/ws.php =================================================================== --- web/php/trunk/ws.php 2011-07-17 02:26:54 UTC (rev 313307) +++ web/php/trunk/ws.php 2011-07-17 04:17:46 UTC (rev 313308) @@ -39,6 +39,7 @@ // mtime is stored on the first line of the result file to // avoid needing to call clearstatcache() function limited_intermediate_result_cache($url,$ttl=1800, &$error=NULL) { + global $cached; $cfile = '/var/tmp/bing_'.md5($url).'.json'; $mtime = 0; $data = ''; @@ -63,6 +64,7 @@ if(strlen($data)) return $data; else return false; } else $data = $tmp; + $cached = 1; $fp = fopen($cfile, 'w'); fputs($fp, $_SERVER['REQUEST_TIME']."\n"); fputs($fp, $data); @@ -74,6 +76,7 @@ $request = "{$conf['svc']}?appid={$conf['appid']}&query=$q%20site:{$sites[$scope]}&version=2.2&Sources=Web&web.offset=$s&web.count=$r&market=$market"; $error = ''; +$cached = 0; $data = limited_intermediate_result_cache($request, 1800, $error); if($data) echo ws_bing_massage($data); else echo serialize($error); @@ -112,8 +115,8 @@ PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { - $stmt = $dbh->prepare("INSERT INTO log (query,profile,mirror,lang) VALUES (:query,:profile,:mirror,:lang)"); - $stmt->execute(array(':query'=>$raw,':profile'=>$scope,':mirror'=>$m,':lang'=>$l)); + $stmt = $dbh->prepare("INSERT INTO log (query,profile,mirror,lang,cached) VALUES (:query,:profile,:mirror,:lang,:cached)"); + $stmt->execute(array(':query'=>$raw,':profile'=>$scope,':mirror'=>$m,':lang'=>$l,':cached'=>$cached)); } catch (PDOException $e) { }

« previous php.webmaster (#11674) next »