comparison php/read/similar.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
104 $crl = curl_init(); 104 $crl = curl_init();
105 $timeout = 5; 105 $timeout = 5;
106 curl_setopt ($crl, CURLOPT_URL,$url); 106 curl_setopt ($crl, CURLOPT_URL,$url);
107 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); 107 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
108 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); 108 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
109 $gotit=0;
110 $semaphore = new SyncSemaphore("Amazon");
111 $gotit = $semaphore->lock(4000);
112 if (!$gotit) {
113 file_put_contents('/var/ywww/debug/phpDebug',
114 "Got it: ".(int)$gotit." 4\n",FILE_APPEND);
115 $gotit = $semaphore->lock(5000);
116 file_put_contents('/var/ywww/debug/phpDebug',
117 "Got it: ".(int)$gotit." $requestIP 4a\n",FILE_APPEND);
118 }
109 $ret = curl_exec($crl); 119 $ret = curl_exec($crl);
110 curl_close($crl); 120 curl_close($crl);
121 usleep(1000000);
122 if ($gotit) {
123 $semaphore->unlock();
124 }
125 else {
126 file_put_contents('/var/ywww/debug/phpDebug',
127 "Unlocking 4\n",FILE_APPEND);
128 }
111 //echo $ret; 129 //echo $ret;
112 130
113 $xml = new SimpleXMLElement($ret); 131 $xml = new SimpleXMLElement($ret);
114 132
115 //$isbn1 = $xml->Items->Request->SimilarityLookupRequest->ItemId; 133 //$isbn1 = $xml->Items->Request->SimilarityLookupRequest->ItemId;