Mercurial > hg > ywww
comparison xml/amazonBookSearch.php @ 30:b1bbf44c701b
standarise semaphore use
author | Robert Boland <robert@markup.co.uk> |
---|---|
date | Fri, 04 Jan 2019 08:50:23 -0500 |
parents | d606320ec331 |
children | dbc006408d2b |
comparison
equal
deleted
inserted
replaced
29:f024f2f08994 | 30:b1bbf44c701b |
---|---|
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; | 96 $gotit=0; |
97 $semaphore = new SyncSemaphore("Amazon"); | 97 $semaphore = new SyncSemaphore("Amazon"); |
98 $gotit = $semaphore->lock(1000); | 98 $gotit = $semaphore->lock(1000); |
99 file_put_contents('/var/ywww/debug/phpDebug', | 99 if (!$gotit) { |
100 "Got it: ".(int)$gotit." 3\n",FILE_APPEND); | 100 file_put_contents('/var/ywww/debug/phpDebug', |
101 if (!$gotit) { $gotit = $semaphore->lock(1000); } | 101 "Got it: ".(int)$gotit." 3\n",FILE_APPEND); |
102 $gotit=$semaphore->lock(1000); | |
103 file_put_contents('/var/ywww/debug/phpDebug', | |
104 "Got it: ".(int)$gotit." 3a\n",FILE_APPEND); | |
105 } | |
102 $ret = curl_exec($crl); | 106 $ret = curl_exec($crl); |
103 curl_close($crl); | 107 curl_close($crl); |
108 usleep(500000); | |
104 if ($gotit) { | 109 if ($gotit) { |
105 usleep(500000); | |
106 file_put_contents('/var/ywww/debug/phpDebug',"Unlocking 3\n",FILE_APPEND); | |
107 $semaphore->unlock(); | 110 $semaphore->unlock(); |
108 } | 111 } |
112 else { | |
113 file_put_contents('/var/ywww/debug/phpDebug',"W/o lock 3b\n",FILE_APPEND); | |
114 } | |
109 echo $ret; | 115 echo $ret; |