comparison xml/amazonBookSearch.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 ae1459564f66
children d606320ec331
comparison
equal deleted inserted replaced
20:7679346abfdb 21:46382face560
91 $timeout = 5; 91 $timeout = 5;
92 curl_setopt ($crl, CURLOPT_URL,$url); 92 curl_setopt ($crl, CURLOPT_URL,$url);
93 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); 93 curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
94 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); 94 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
95 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); 95 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
96 $gotit=0;
97 $semaphore = new SyncSemaphore("Amazon");
98 $gotit = $semaphore->lock(4000);
99 file_put_contents('/var/ywww/debug/phpDebug',
100 "Got it: ".(int)$gotit." 3\n",FILE_APPEND);
101 if (!$gotit) { $gotit = $semaphore->lock(20000); }
96 $ret = curl_exec($crl); 102 $ret = curl_exec($crl);
97 curl_close($crl); 103 curl_close($crl);
104 if ($gotit) {
105 usleep(1000000);
106 file_put_contents('/var/ywww/debug/phpDebug',"Unlocking 3\n",FILE_APPEND);
107 $semaphore->unlock();
108 }
98 echo $ret; 109 echo $ret;