Mercurial > hg > ywww
annotate xml/getAmazonInfo.php @ 23:d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
author | Charlie Root |
---|---|
date | Sun, 30 Dec 2018 07:00:09 -0500 |
parents | 46382face560 |
children | 828895488948 |
rev | line source |
---|---|
4 | 1 <?php |
2 | |
5 | 3 $lastReqTime=0; |
4 | 4 function getAmazonDet($isbn,$go,$localeIn) |
5 { | |
6 global $output; | |
7 $Adefault=array( | |
8 'language' =>'en', //what language to render the page in | |
9 'locale' =>$localeIn, //which server's products? available: ca,de,fr,jp,uk,us | |
10 //'mode' =>'books', //what product category? | |
11 'page' =>1, //first page to show (we are counting from 1 not 0) | |
12 //'search' =>'Machiavelli', //what to search for? | |
13 'operation' =>'ItemLookup', //what to do? //ItemSearch | |
14 // 'searchindex' =>'Books', //what product category for search? | |
15 'searchparameter' =>'ItemId', //what kind of search? | |
16 'searchparameterdata'=>$isbn, //what to search for? | |
17 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' | |
18 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending | |
19 'show_url' =>false, //debug: show XML request url to be send to Amazon? | |
20 'show_xml' =>false, //debug: show incoming XML code from Amazon? | |
21 ); | |
22 //change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it | |
23 | |
24 $Aassociates_id=array( | |
25 'uk' => 'bookwhack-21', | |
26 'us' => 'your02b-20', | |
27 'ca' => 'book009-20', | |
28 'de' => 'book04c-21', | |
29 'fr' => 'book07f-21', | |
30 ); | |
31 | |
32 $Aserver=array( | |
33 'ca' => array( | |
34 'ext' => 'ca' , //Canadian normal server | |
35 'nor' => 'http://www.amazon.ca' , //Canadian normal server | |
36 'xml' => 'http://xml.amazon.com' , //Canadian xml server | |
37 ), | |
38 'de' => array( | |
39 'ext' => 'de' , //German normal server | |
40 'nor' => 'http://www.amazon.de' , //German normal server | |
41 'xml' => 'http://xml-eu.amazon.com', //German xml server | |
42 ), | |
43 'fr' => array( | |
44 'ext' => 'fr' , //French normal server | |
45 'nor' => 'http://www.amazon.fr' , //French normal server | |
46 'xml' => 'http://xml-eu.amazon.com', //French xml server | |
47 ), | |
48 'jp' => array( | |
49 'ext' => 'jp' , //Japanese normal server, not co.jp! | |
50 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server | |
51 'xml' => 'http://xml.amazon.com' , //Japanese xml server | |
52 ), | |
53 'uk' => array( | |
54 'ext' => 'co.uk' , //UK normal server | |
55 'nor' => 'http://www.amazon.co.uk' , //UK normal server | |
56 'xml' => 'http://xml-eu.amazon.com', //UK xml server | |
57 ), | |
58 'us' => array( | |
59 'ext' => 'com' , //USA normal server | |
60 'nor' => 'http://www.amazon.com' , //USA normal server | |
61 'xml' => 'http://xml.amazon.com' , //USA xml server | |
62 ), | |
63 ); | |
64 | |
65 //if(go != 1) | |
66 //include "aws_signed_request.php"; | |
17
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
11
diff
changeset
|
67 $public_key ="AKIAIHTNWC7L6LOUY4LQ"; |
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
11
diff
changeset
|
68 $private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde"; |
4 | 69 //for all parameters see if the user has overruled it or use the default |
70 foreach ($Adefault as $i=>$d) { | |
71 $$i=isset($_GET[$i])?$_GET[$i]:$d; | |
72 } | |
73 //this is the data that is used to form the request for AWS | |
74 //this is the part that is search specific | |
75 $parameters=array( | |
76 'Operation' =>$operation , | |
77 //'Keywords' =>urlencode($search) , | |
78 //'SearchIndex' =>$searchindex , //Books for example. | |
79 "$searchparameter"=>$searchparameterdata , | |
80 'ItemPage' =>$page , //which page? | |
81 'AssociateTag' =>$Aassociates_id[$locale], | |
82 'ResponseGroup' =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes' , //Small, Medium, Large or SellerListing,'BrowseNodes',// , | |
83 'ReviewSort' =>'-HelpfulVotes' | |
84 ); | |
85 | |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
86 $requestURI = $_SERVER['REQUEST_URI']; |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
87 $requestIP = $_SERVER['REMOTE_ADDR']; |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
88 // if ($requestIP=="173.161.113.65" || $requestIP=="141.8.132.25") { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
89 // $delay=60; |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
90 // file_put_contents('/var/ywww/debug/phpDebug', |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
91 // "bad guy: $requestIP, $requestURI\n", |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
92 // FILE_APPEND); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
93 // sleep($delay); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
94 // # No, can't do this |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
95 // # return; # bomb! |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
96 // # 'Kung', sitting on my desk in the office while I'm at home, |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
97 // # is occasionally hitting xml/getAmazonInfo.php: |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
98 // # e.g. Losing: ItemLookupErrorResponse, RequestThrottled, 129.215.197.36, /xml/getAmazonInfo.php?searchparameterdata=075154454X&locale=uk |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
99 // # repeatedly, same params |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
100 // } |
4 | 101 $ext=$Aserver[$locale]['ext']; |
102 $file_data=$ext; | |
103 ksort($parameters); | |
104 foreach ($parameters as $i=>$d) { | |
105 $file_data.='&'.$i.'='.$d; | |
106 } | |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
107 $gotit=0; |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
108 $url=aws_signed_request($ext,$parameters,$public_key,$private_key); |
4 | 109 $crl = curl_init(); |
110 $timeout = 5; | |
111 curl_setopt ($crl, CURLOPT_URL,$url); | |
112 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
113 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
114 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
115 $semaphore = new SyncSemaphore("Amazon"); |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
116 $gotit = $semaphore->lock(1000); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
117 if (!$gotit) { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
118 file_put_contents('/var/ywww/debug/phpDebug', |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
119 "Got it: ".(int)$gotit." $requestIP 1\n",FILE_APPEND); |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
120 $gotit=$semaphore->lock(1000); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
121 file_put_contents('/var/ywww/debug/phpDebug', |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
122 "Got it: ".(int)$gotit." $requestIP 1a\n",FILE_APPEND); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
123 } |
4 | 124 $output = curl_exec($crl); |
125 curl_close($crl); | |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
126 usleep(500000); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
127 if ($gotit) { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
128 $semaphore->unlock(); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
129 } |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
130 else { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
131 file_put_contents('/var/ywww/debug/phpDebug', |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
132 "W/o lock for $requestIP 1b\n",FILE_APPEND); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
133 } |
4 | 134 $review = ""; |
19 | 135 $review1 = ""; |
136 $review2 = ""; | |
137 $review3 = ""; | |
5 | 138 // HST added this |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
139 $mm=array(); |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
140 if (preg_match("<Error>",$output,$mm)) { |
5 | 141 $xml = new SimpleXMLElement($output); |
142 $resName=$xml->getName(); | |
143 $code=$xml->Error->Code; | |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
144 if (!$code) { |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
145 $code=$xml->Items->Request->Errors->Error->Code; |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
146 } |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
147 file_put_contents('/var/ywww/debug/phpDebug',"Losing: ".$mm[0].", $resName, $code, $requestIP, $requestURI\n",FILE_APPEND); |
7
1dfe64e365a0
a bit more debugging/bomb-proofing
Robert Boland <robert@markup.co.uk>
parents:
5
diff
changeset
|
148 if ($code=='RequestThrottled') { |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
149 usleep(200000); // Try to reduce throttling until we get a |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
150 // principled solution in place |
7
1dfe64e365a0
a bit more debugging/bomb-proofing
Robert Boland <robert@markup.co.uk>
parents:
5
diff
changeset
|
151 } |
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
152 else { |
18 | 153 file_put_contents('/var/ywww/debug/phpDebug',"parms: $go\nurl: $url\n". |
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
154 print_r($parameters,TRUE)."\n",FILE_APPEND); |
10
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
155 if ($code=="") { |
11
c9ebf871114b
fix wrong var in debug output
Henry S. Thompson <ht@markup.co.uk>
parents:
10
diff
changeset
|
156 file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$output\n",FILE_APPEND); |
10
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
157 } |
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
7
diff
changeset
|
158 } |
5 | 159 } |
160 else { | |
161 $xml = new SimpleXMLElement($output); | |
162 set_error_handler(function () { | |
163 global $output; | |
164 file_put_contents('/var/ywww/debug/phpDebug', | |
165 "Caught one?: ".$searchparameterdata, | |
166 FILE_APPEND); | |
167 file_put_contents('/var/ywww/debug/phpDebug', | |
168 print_r($output, TRUE)."\n", | |
169 FILE_APPEND); | |
4 | 170 } ); |
5 | 171 $review = $xml->Items->Item->CustomerReviews->IFrameURL; |
172 // The above is failing repeatedly -- | |
173 //PHP Notice: Trying to get property of non-object in | |
174 // /var/ywww/xml/getAmazonInfo.php on line [109] | |
175 // See the dumped structure at the end of this file for the | |
176 // cause | |
177 restore_error_handler(); | |
178 //echo $review; | |
179 } | |
4 | 180 if ($review != "") |
181 { | |
182 $text = @file_get_contents($review . "&truncate=300"); | |
183 $removeTop1 = preg_replace('~<div class="crIFrameHeaderLeftColumn">(.*?)<div class="crIFrameHeaderHistogram">~si', '', $text); | |
184 $removeTop2 = preg_replace('~<div class="crIFrameHeaderHistogram">(.*?)<div class="crIframeReviewList">~si', '', $text); | |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
185 if (preg_match('~<body[^>]*>(.*?)</body>~si', $removeTop2, $body)){ $getBody = trim($body[1]); } else { $getBody = $removeTop2;} |
4 | 186 $removeDiv = preg_replace('~<div[^>]*>(.*?)</div>~si', '', $getBody); |
187 $removeCloseDivs = preg_replace('/<\/div>/','', $removeDiv); | |
188 $setBoundary = str_replace('<!-- BOUNDARY -->','BOTTOM-TOP', $removeCloseDivs); | |
189 //replace <!-- BOUNDARY --> with BOTTOM-TOP | |
190 $remove1 = '~<table cellpadding="0"(.*?)%">~s'; | |
191 $setBoundary = preg_replace($remove1,'', $setBoundary); | |
192 $remove2 = '~</td><td bg(.*?)</table>~s'; | |
193 $setBoundary = preg_replace($remove2,'', $setBoundary); | |
194 $remove3 = '~<a name=(.*?)</a>~s'; | |
195 $setBoundary = preg_replace($remove3,'', $setBoundary); | |
196 $setBoundary2 = str_replace('<br />','', $setBoundary); | |
197 //remove all extra crap; | |
198 $setBoundary3 = str_replace('</td>','BOTTOM', $setBoundary2); | |
199 //replace </td> with BOTTOM | |
200 | |
201 if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews)) | |
202 { | |
203 $reviewContents = $reviews[1]; | |
204 //print_r($reviewContents); | |
205 $review1 = trim($reviewContents[0]); | |
206 $review1 = str_replace("\n", "", $review1); | |
207 $review1 = str_replace("\r", "", $review1); | |
208 if (isset($reviewContents[1])) { | |
209 $review2 = trim($reviewContents[1]); | |
210 $review2 = str_replace("\n", "", $review2); | |
211 $review2 = str_replace("\r", "", $review2); | |
212 } | |
213 else { | |
214 $review2 = ""; | |
215 } | |
216 if (isset($reviewContents[2])) { | |
217 $review3 = trim($reviewContents[2]); | |
218 $review3 = str_replace("\n", "", $review3); | |
219 $review3 = str_replace("\r", "", $review3); | |
220 } | |
221 else { | |
222 $review3 = ""; | |
223 } | |
224 } | |
225 else | |
226 { | |
227 $review1 = ""; | |
228 $review2 = ""; | |
229 $review3 = ""; | |
230 //echo "EPIC FAIL"; | |
231 } | |
232 | |
233 unset($xml->Items->Item->CustomerReviews); | |
234 $xdoc = new DomDocument; | |
235 $xdoc->loadXML($xml->asXML()); | |
236 | |
237 $cReviews = $xdoc ->createElement('CustomerReviews'); | |
238 $cReviewHolder = $xdoc ->createElement('Review'); | |
239 $cReview = $xdoc ->createElement('Content'); | |
240 $cReviewHolder2 = $xdoc ->createElement('Review'); | |
241 $cReview2 = $xdoc ->createElement('Content'); | |
242 $cReviewHolder3 = $xdoc ->createElement('Review'); | |
243 $cReview3 = $xdoc ->createElement('Content'); | |
244 | |
245 $txtNode = $xdoc ->createTextNode ($review1); | |
246 $cReview -> appendChild($txtNode); | |
247 | |
248 $txtNode2 = $xdoc ->createTextNode ($review2); | |
249 $cReview2 -> appendChild($txtNode2); | |
250 | |
251 $txtNode3 = $xdoc ->createTextNode ($review3); | |
252 $cReview3 -> appendChild($txtNode3); | |
253 | |
254 $cReviewHolder -> appendChild($cReview); | |
255 $cReviewHolder2 -> appendChild($cReview2); | |
256 $cReviewHolder3 -> appendChild($cReview3); | |
257 | |
258 $cReviews -> appendChild($cReviewHolder); | |
259 $cReviews -> appendChild($cReviewHolder2); | |
260 $cReviews -> appendChild($cReviewHolder3); | |
261 | |
262 $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews); | |
263 $newXML = simplexml_import_dom($xdoc); | |
264 $output = $newXML->asXml(); | |
265 } | |
266 | |
267 switch($locale){ | |
268 case "us": | |
269 $loc = 0; | |
270 break; | |
271 case "uk": | |
272 $loc = 1; | |
273 break; | |
274 case "ca": | |
275 $loc = 2; | |
276 break; | |
277 case "de": | |
278 $loc = 3; | |
279 break; | |
280 case "fr": | |
281 $loc = 4; | |
282 break; | |
283 }; | |
284 | |
285 $errorCode = $xml->Error->Code; | |
286 //echo $errorCode; | |
287 | |
288 if($errorCode != "AccountLimitExceeded") | |
289 { | |
5 | 290 if($go == 1) { |
19 | 291 $item = $xml->Items->Item[0]; |
292 if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) { | |
293 $title = $item->ItemAttributes->Title; } | |
294 else { $title = "[no title]"; }; | |
5 | 295 file_put_contents('/var/ywww/debug/phpDebug',"win: ". |
19 | 296 $title."\n", |
5 | 297 FILE_APPEND); |
4 | 298 return $output; |
5 | 299 } |
19 | 300 else |
301 { | |
302 if ($xml->Items->Item) { | |
303 $title = $xml->Items->Item[0]->ItemAttributes->Title; | |
304 $author = $xml->Items->Item[0]->ItemAttributes->Author; | |
305 $binding = $xml->Items->Item[0]->ItemAttributes->Binding; | |
306 $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber; | |
307 if($dewey == "") | |
308 $dewey = "null"; | |
309 $imageURL = $xml->Items->Item[0]->MediumImage->URL; | |
310 $salesRank = $xml->Items->Item[0]->SalesRank; | |
311 $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate; | |
312 $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher; | |
313 } | |
314 else { | |
315 $title = $salesRank = ""; | |
316 $dewey = "null"; | |
317 } | |
4 | 318 |
19 | 319 $genreID = ""; |
320 $genre = ""; | |
321 $genArr = array(); | |
322 | |
323 if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) { | |
324 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ | |
325 //sexy recursive function | |
326 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); | |
4 | 327 |
19 | 328 if($genre != "") |
329 $genArr[strval($genreID)] = strval($genre); | |
330 //$genArr[$i] = array(strval($genreID) => strval($genre)); | |
4 | 331 |
19 | 332 //echo $genre; |
333 //echo $genreID; | |
4 | 334 |
19 | 335 $genre = ""; |
336 $genreID = ""; | |
337 } | |
338 } | |
4 | 339 |
19 | 340 $g1 = "null"; |
341 $g2 = "null"; | |
342 $g3 = "null"; | |
343 $loop = 1; | |
4 | 344 |
19 | 345 foreach ($genArr as $key => $value) { |
346 //echo "$key => $value"; | |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
347 if ($key>2047) { |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
348 //HST added |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
349 break; |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
350 } |
19 | 351 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table |
352 //echo $queryG; | |
353 include "../../private/db.php"; | |
354 $resG = mysqli_query($link, $queryG); | |
355 mysqli_close($link); | |
4 | 356 |
19 | 357 switch ($loop) { |
358 case 1: | |
359 $g1 = $key; | |
360 break; | |
361 case 2: | |
362 $g2 = $key; | |
363 break; | |
364 case 3: | |
365 $g3 = $key; | |
366 break; | |
367 } | |
4 | 368 |
19 | 369 $loop++; |
370 } | |
4 | 371 |
19 | 372 if($salesRank == "") |
373 $salesRank = "null"; | |
4 | 374 |
19 | 375 $title = strtr($title, '"', "'"); |
376 include "../../private/db.php"; | |
377 $review1 = mysqli_real_escape_string($link,$review1); | |
378 $review2 = mysqli_real_escape_string($link,$review2); | |
379 $review3 = mysqli_real_escape_string($link,$review3); | |
4 | 380 |
19 | 381 if($title != "") |
382 { | |
383 $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; | |
384 //echo $queryInsert; | |
385 $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")"; | |
4 | 386 |
19 | 387 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); |
388 if($review1 != "" && $review2 != "" && $review3 != "") | |
389 $resG = mysqli_query($link, $queryInsertReviews) or exit( mysqli_error( $link )); | |
4 | 390 |
19 | 391 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
392 } | |
4 | 393 |
19 | 394 echo $output; |
395 } | |
4 | 396 } |
397 else | |
398 { | |
399 //look up info from db | |
400 include "../../private/db.php"; | |
401 $query = "CALL b_getBookInfo('$searchparameterdata', $loc)"; | |
402 //echo $query; | |
403 $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); | |
404 | |
405 $output = ""; | |
406 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | |
407 $output .= "<Details>"; | |
408 if ( mysqli_num_rows( $res ) > 0 ) | |
409 { | |
410 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); | |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
411 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
4 | 412 $output .= "<ASIN>" . $searchparameterdata . "</ASIN>"; |
413 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>"; | |
414 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>"; | |
415 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>"; | |
416 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>"; | |
417 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>"; | |
418 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>"; | |
419 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>"; | |
420 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>"; | |
421 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>"; | |
422 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>"; | |
423 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>"; | |
424 $output .= "<ProductGroup>Book</ProductGroup>"; | |
425 $output .= "<Error>AccountLimitExceeded</Error>"; | |
426 | |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
427 } |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
428 else { |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
429 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
430 } |
4 | 431 $output .= "</Details>"; |
432 echo $output; | |
433 } | |
434 } | |
435 | |
436 function findGenre($browseNode, &$ID, &$gen) | |
437 { | |
438 if($browseNode->Name == "Subjects") | |
439 { | |
440 return true; | |
441 } | |
442 else | |
443 { | |
444 if($browseNode->Ancestors->BrowseNode) | |
445 { | |
446 if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true) | |
447 { | |
448 $gen = $browseNode->Name; | |
449 $ID = $browseNode->BrowseNodeId; | |
450 } | |
451 } | |
452 return false; | |
453 } | |
454 } | |
455 | |
456 if(!isset($ret)) | |
457 { | |
458 include "aws_signed_request.php"; | |
459 getAmazonDet('default',0,'us'); //will get overwritten | |
460 } | |
461 /*Caught oneSimpleXMLElement Object | |
462 ( | |
463 [OperationRequest] => SimpleXMLElement Object | |
464 ( | |
465 [RequestId] => d2eaacba-2411-44e7-b268-f23a20167330 | |
466 [Arguments] => SimpleXMLElement Object | |
467 ( | |
468 [Argument] => Array | |
469 ( | |
470 [0] => SimpleXMLElement Object | |
471 ( | |
472 [@attributes] => Array | |
473 ( | |
474 [Name] => AWSAccessKeyId | |
17
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
11
diff
changeset
|
475 [Value] => AKIAIHTNWC7L6LOUY4LQ |
4 | 476 ) |
477 | |
478 ) | |
479 | |
480 [1] => SimpleXMLElement Object | |
481 ( | |
482 [@attributes] => Array | |
483 ( | |
484 [Name] => AssociateTag | |
485 [Value] => bookwhack-21 | |
486 ) | |
487 | |
488 ) | |
489 | |
490 [2] => SimpleXMLElement Object | |
491 ( | |
492 [@attributes] => Array | |
493 ( | |
494 [Name] => ItemId | |
495 [Value] => B004Q3Q3Y4 | |
496 ) | |
497 | |
498 ) | |
499 | |
500 [3] => SimpleXMLElement Object | |
501 ( | |
502 [@attributes] => Array | |
503 ( | |
504 [Name] => ItemPage | |
505 [Value] => 1 | |
506 ) | |
507 | |
508 ) | |
509 | |
510 [4] => SimpleXMLElement Object | |
511 ( | |
512 [@attributes] => Array | |
513 ( | |
514 [Name] => Operation | |
515 [Value] => ItemLookup | |
516 ) | |
517 | |
518 ) | |
519 | |
520 [5] => SimpleXMLElement Object | |
521 ( | |
522 [@attributes] => Array | |
523 ( | |
524 [Name] => ResponseGroup | |
525 [Value] => ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes | |
526 ) | |
527 | |
528 ) | |
529 | |
530 [6] => SimpleXMLElement Object | |
531 ( | |
532 [@attributes] => Array | |
533 ( | |
534 [Name] => ReviewSort | |
535 [Value] => -HelpfulVotes | |
536 ) | |
537 | |
538 ) | |
539 | |
540 [7] => SimpleXMLElement Object | |
541 ( | |
542 [@attributes] => Array | |
543 ( | |
544 [Name] => Service | |
545 [Value] => AWSECommerceService | |
546 ) | |
547 | |
548 ) | |
549 | |
550 [8] => SimpleXMLElement Object | |
551 ( | |
552 [@attributes] => Array | |
553 ( | |
554 [Name] => Timestamp | |
555 [Value] => 2016-12-15T23:12:34Z | |
556 ) | |
557 | |
558 ) | |
559 | |
560 [9] => SimpleXMLElement Object | |
561 ( | |
562 [@attributes] => Array | |
563 ( | |
564 [Name] => Version | |
565 [Value] => 2011-08-01 | |
566 ) | |
567 | |
568 ) | |
569 | |
570 [10] => SimpleXMLElement Object | |
571 ( | |
572 [@attributes] => Array | |
573 ( | |
574 [Name] => Signature | |
575 [Value] => SUXfFZHQ74Joc+WDLx87uzemTdtHijNohykqafJXYKQ= | |
576 ) | |
577 | |
578 ) | |
579 | |
580 ) | |
581 | |
582 ) | |
583 | |
584 [RequestProcessingTime] => 0.3518217620000000 | |
585 ) | |
586 | |
587 [Items] => SimpleXMLElement Object | |
588 ( | |
589 [Request] => SimpleXMLElement Object | |
590 ( | |
591 [IsValid] => True | |
592 [ItemLookupRequest] => SimpleXMLElement Object | |
593 ( | |
594 [IdType] => ASIN | |
595 [ItemId] => B004Q3Q3Y4 | |
596 [ResponseGroup] => Array | |
597 ( | |
598 [0] => ItemAttributes | |
599 [1] => Reviews | |
600 [2] => EditorialReview | |
601 [3] => OfferSummary | |
602 [4] => Offers | |
603 [5] => Images | |
604 [6] => AlternateVersions | |
605 [7] => SalesRank | |
606 [8] => BrowseNodes | |
607 ) | |
608 | |
609 [VariationPage] => All | |
610 ) | |
611 | |
612 [Errors] => SimpleXMLElement Object | |
613 ( | |
614 [Error] => SimpleXMLElement Object | |
615 ( | |
616 [Code] => AWS.InvalidParameterValue | |
617 [Message] => B004Q3Q3Y4 is not a valid value for ItemId. Please change this value and retry your request. | |
618 ) | |
619 | |
620 ) | |
621 | |
622 ) | |
623 | |
624 ) | |
625 | |
626 ) | |
627 */ | |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
19
diff
changeset
|
628 /*$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><ItemLookupErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2009-03-31/\"><Error><Code>AccountLimitExceeded</Code><Message>Account limit of 2056 requests per hour exceeded.</Message></Error><RequestID>290ed059-730c-4789-93b4-6d21e11053d3</RequestID></ItemLookupErrorResponse>");*/ |
4 | 629 ?> |