Mercurial > hg > ywww
diff php/read/getBookDetails.php @ 21:46382face560
use a semaphore to try to cut down on RequestThrottled fails
author | Charlie Root |
---|---|
date | Thu, 25 Oct 2018 09:42:12 -0400 |
parents | c41a5802b26c |
children | d606320ec331 |
line wrap: on
line diff
--- a/php/read/getBookDetails.php Thu Oct 25 09:40:25 2018 -0400 +++ b/php/read/getBookDetails.php Thu Oct 25 09:42:12 2018 -0400 @@ -204,16 +204,35 @@ curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); + $gotit=0; + $requestIP = $_SERVER['REMOTE_ADDR']; + $semaphore = new SyncSemaphore("Amazon"); + $gotit = $semaphore->lock(4000); + if (!$gotit) { + file_put_contents('/var/ywww/debug/phpDebug', + "Got it: ".(int)$gotit." $requestIP 2\n",FILE_APPEND); + $gotit=$semaphore->lock(5000); + file_put_contents('/var/ywww/debug/phpDebug', + "Got it: ".(int)$gotit." $requestIP 2a\n",FILE_APPEND); + } $out = curl_exec($crl); curl_close($crl); - + usleep(1000000); + if ($gotit) { + $semaphore->unlock(); + } + else { + file_put_contents('/var/ywww/debug/phpDebug', + "W/o lock for $requestIP 2b\n",FILE_APPEND); + } //echo $out; if (preg_match("<Error>",$out)) { $xml = new SimpleXMLElement($out); $resName=$xml->getName(); $code=$xml->Error->Code; - file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code\n",FILE_APPEND); + $requestIP = $_SERVER['REMOTE_ADDR']; + file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code, $requestIP\n",FILE_APPEND); if ($code=='RequestThrottled') { usleep(200000); // Try to reduce throttling until we get a // principled solution in place