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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
a6b55ae70617 original
robert
parents:
diff changeset
1 <?php
a6b55ae70617 original
robert
parents:
diff changeset
2
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
3 $lastReqTime=0;
4
a6b55ae70617 original
robert
parents:
diff changeset
4 function getAmazonDet($isbn,$go,$localeIn)
a6b55ae70617 original
robert
parents:
diff changeset
5 {
a6b55ae70617 original
robert
parents:
diff changeset
6 global $output;
a6b55ae70617 original
robert
parents:
diff changeset
7 $Adefault=array(
a6b55ae70617 original
robert
parents:
diff changeset
8 'language' =>'en', //what language to render the page in
a6b55ae70617 original
robert
parents:
diff changeset
9 'locale' =>$localeIn, //which server's products? available: ca,de,fr,jp,uk,us
a6b55ae70617 original
robert
parents:
diff changeset
10 //'mode' =>'books', //what product category?
a6b55ae70617 original
robert
parents:
diff changeset
11 'page' =>1, //first page to show (we are counting from 1 not 0)
a6b55ae70617 original
robert
parents:
diff changeset
12 //'search' =>'Machiavelli', //what to search for?
a6b55ae70617 original
robert
parents:
diff changeset
13 'operation' =>'ItemLookup', //what to do? //ItemSearch
a6b55ae70617 original
robert
parents:
diff changeset
14 // 'searchindex' =>'Books', //what product category for search?
a6b55ae70617 original
robert
parents:
diff changeset
15 'searchparameter' =>'ItemId', //what kind of search?
a6b55ae70617 original
robert
parents:
diff changeset
16 'searchparameterdata'=>$isbn, //what to search for?
a6b55ae70617 original
robert
parents:
diff changeset
17 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
a6b55ae70617 original
robert
parents:
diff changeset
18 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending
a6b55ae70617 original
robert
parents:
diff changeset
19 'show_url' =>false, //debug: show XML request url to be send to Amazon?
a6b55ae70617 original
robert
parents:
diff changeset
20 'show_xml' =>false, //debug: show incoming XML code from Amazon?
a6b55ae70617 original
robert
parents:
diff changeset
21 );
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
23
a6b55ae70617 original
robert
parents:
diff changeset
24 $Aassociates_id=array(
a6b55ae70617 original
robert
parents:
diff changeset
25 'uk' => 'bookwhack-21',
a6b55ae70617 original
robert
parents:
diff changeset
26 'us' => 'your02b-20',
a6b55ae70617 original
robert
parents:
diff changeset
27 'ca' => 'book009-20',
a6b55ae70617 original
robert
parents:
diff changeset
28 'de' => 'book04c-21',
a6b55ae70617 original
robert
parents:
diff changeset
29 'fr' => 'book07f-21',
a6b55ae70617 original
robert
parents:
diff changeset
30 );
a6b55ae70617 original
robert
parents:
diff changeset
31
a6b55ae70617 original
robert
parents:
diff changeset
32 $Aserver=array(
a6b55ae70617 original
robert
parents:
diff changeset
33 'ca' => array(
a6b55ae70617 original
robert
parents:
diff changeset
34 'ext' => 'ca' , //Canadian normal server
a6b55ae70617 original
robert
parents:
diff changeset
35 'nor' => 'http://www.amazon.ca' , //Canadian normal server
a6b55ae70617 original
robert
parents:
diff changeset
36 'xml' => 'http://xml.amazon.com' , //Canadian xml server
a6b55ae70617 original
robert
parents:
diff changeset
37 ),
a6b55ae70617 original
robert
parents:
diff changeset
38 'de' => array(
a6b55ae70617 original
robert
parents:
diff changeset
39 'ext' => 'de' , //German normal server
a6b55ae70617 original
robert
parents:
diff changeset
40 'nor' => 'http://www.amazon.de' , //German normal server
a6b55ae70617 original
robert
parents:
diff changeset
41 'xml' => 'http://xml-eu.amazon.com', //German xml server
a6b55ae70617 original
robert
parents:
diff changeset
42 ),
a6b55ae70617 original
robert
parents:
diff changeset
43 'fr' => array(
a6b55ae70617 original
robert
parents:
diff changeset
44 'ext' => 'fr' , //French normal server
a6b55ae70617 original
robert
parents:
diff changeset
45 'nor' => 'http://www.amazon.fr' , //French normal server
a6b55ae70617 original
robert
parents:
diff changeset
46 'xml' => 'http://xml-eu.amazon.com', //French xml server
a6b55ae70617 original
robert
parents:
diff changeset
47 ),
a6b55ae70617 original
robert
parents:
diff changeset
48 'jp' => array(
a6b55ae70617 original
robert
parents:
diff changeset
49 'ext' => 'jp' , //Japanese normal server, not co.jp!
a6b55ae70617 original
robert
parents:
diff changeset
50 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server
a6b55ae70617 original
robert
parents:
diff changeset
51 'xml' => 'http://xml.amazon.com' , //Japanese xml server
a6b55ae70617 original
robert
parents:
diff changeset
52 ),
a6b55ae70617 original
robert
parents:
diff changeset
53 'uk' => array(
a6b55ae70617 original
robert
parents:
diff changeset
54 'ext' => 'co.uk' , //UK normal server
a6b55ae70617 original
robert
parents:
diff changeset
55 'nor' => 'http://www.amazon.co.uk' , //UK normal server
a6b55ae70617 original
robert
parents:
diff changeset
56 'xml' => 'http://xml-eu.amazon.com', //UK xml server
a6b55ae70617 original
robert
parents:
diff changeset
57 ),
a6b55ae70617 original
robert
parents:
diff changeset
58 'us' => array(
a6b55ae70617 original
robert
parents:
diff changeset
59 'ext' => 'com' , //USA normal server
a6b55ae70617 original
robert
parents:
diff changeset
60 'nor' => 'http://www.amazon.com' , //USA normal server
a6b55ae70617 original
robert
parents:
diff changeset
61 'xml' => 'http://xml.amazon.com' , //USA xml server
a6b55ae70617 original
robert
parents:
diff changeset
62 ),
a6b55ae70617 original
robert
parents:
diff changeset
63 );
a6b55ae70617 original
robert
parents:
diff changeset
64
a6b55ae70617 original
robert
parents:
diff changeset
65 //if(go != 1)
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
69 //for all parameters see if the user has overruled it or use the default
a6b55ae70617 original
robert
parents:
diff changeset
70 foreach ($Adefault as $i=>$d) {
a6b55ae70617 original
robert
parents:
diff changeset
71 $$i=isset($_GET[$i])?$_GET[$i]:$d;
a6b55ae70617 original
robert
parents:
diff changeset
72 }
a6b55ae70617 original
robert
parents:
diff changeset
73 //this is the data that is used to form the request for AWS
a6b55ae70617 original
robert
parents:
diff changeset
74 //this is the part that is search specific
a6b55ae70617 original
robert
parents:
diff changeset
75 $parameters=array(
a6b55ae70617 original
robert
parents:
diff changeset
76 'Operation' =>$operation ,
a6b55ae70617 original
robert
parents:
diff changeset
77 //'Keywords' =>urlencode($search) ,
a6b55ae70617 original
robert
parents:
diff changeset
78 //'SearchIndex' =>$searchindex , //Books for example.
a6b55ae70617 original
robert
parents:
diff changeset
79 "$searchparameter"=>$searchparameterdata ,
a6b55ae70617 original
robert
parents:
diff changeset
80 'ItemPage' =>$page , //which page?
a6b55ae70617 original
robert
parents:
diff changeset
81 'AssociateTag' =>$Aassociates_id[$locale],
a6b55ae70617 original
robert
parents:
diff changeset
82 'ResponseGroup' =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes' , //Small, Medium, Large or SellerListing,'BrowseNodes',// ,
a6b55ae70617 original
robert
parents:
diff changeset
83 'ReviewSort' =>'-HelpfulVotes'
a6b55ae70617 original
robert
parents:
diff changeset
84 );
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
101 $ext=$Aserver[$locale]['ext'];
a6b55ae70617 original
robert
parents:
diff changeset
102 $file_data=$ext;
a6b55ae70617 original
robert
parents:
diff changeset
103 ksort($parameters);
a6b55ae70617 original
robert
parents:
diff changeset
104 foreach ($parameters as $i=>$d) {
a6b55ae70617 original
robert
parents:
diff changeset
105 $file_data.='&'.$i.'='.$d;
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
109 $crl = curl_init();
a6b55ae70617 original
robert
parents:
diff changeset
110 $timeout = 5;
a6b55ae70617 original
robert
parents:
diff changeset
111 curl_setopt ($crl, CURLOPT_URL,$url);
a6b55ae70617 original
robert
parents:
diff changeset
112 curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
a6b55ae70617 original
robert
parents:
diff changeset
113 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
124 $output = curl_exec($crl);
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
134 $review = "";
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
135 $review1 = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
136 $review2 = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
137 $review3 = "";
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
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
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
141 $xml = new SimpleXMLElement($output);
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
142 $resName=$xml->getName();
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
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
c41a5802b26c better debugging
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
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
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
159 }
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
160 else {
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
161 $xml = new SimpleXMLElement($output);
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
162 set_error_handler(function () {
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
163 global $output;
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
164 file_put_contents('/var/ywww/debug/phpDebug',
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
165 "Caught one?: ".$searchparameterdata,
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
166 FILE_APPEND);
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
167 file_put_contents('/var/ywww/debug/phpDebug',
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
168 print_r($output, TRUE)."\n",
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
169 FILE_APPEND);
4
a6b55ae70617 original
robert
parents:
diff changeset
170 } );
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
171 $review = $xml->Items->Item->CustomerReviews->IFrameURL;
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
172 // The above is failing repeatedly --
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
173 //PHP Notice: Trying to get property of non-object in
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
174 // /var/ywww/xml/getAmazonInfo.php on line [109]
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
175 // See the dumped structure at the end of this file for the
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
176 // cause
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
177 restore_error_handler();
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
178 //echo $review;
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
179 }
4
a6b55ae70617 original
robert
parents:
diff changeset
180 if ($review != "")
a6b55ae70617 original
robert
parents:
diff changeset
181 {
a6b55ae70617 original
robert
parents:
diff changeset
182 $text = @file_get_contents($review . "&truncate=300");
a6b55ae70617 original
robert
parents:
diff changeset
183 $removeTop1 = preg_replace('~<div class="crIFrameHeaderLeftColumn">(.*?)<div class="crIFrameHeaderHistogram">~si', '', $text);
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
186 $removeDiv = preg_replace('~<div[^>]*>(.*?)</div>~si', '', $getBody);
a6b55ae70617 original
robert
parents:
diff changeset
187 $removeCloseDivs = preg_replace('/<\/div>/','', $removeDiv);
a6b55ae70617 original
robert
parents:
diff changeset
188 $setBoundary = str_replace('<!-- BOUNDARY -->','BOTTOM-TOP', $removeCloseDivs);
a6b55ae70617 original
robert
parents:
diff changeset
189 //replace <!-- BOUNDARY --> with BOTTOM-TOP
a6b55ae70617 original
robert
parents:
diff changeset
190 $remove1 = '~<table cellpadding="0"(.*?)%">~s';
a6b55ae70617 original
robert
parents:
diff changeset
191 $setBoundary = preg_replace($remove1,'', $setBoundary);
a6b55ae70617 original
robert
parents:
diff changeset
192 $remove2 = '~</td><td bg(.*?)</table>~s';
a6b55ae70617 original
robert
parents:
diff changeset
193 $setBoundary = preg_replace($remove2,'', $setBoundary);
a6b55ae70617 original
robert
parents:
diff changeset
194 $remove3 = '~<a name=(.*?)</a>~s';
a6b55ae70617 original
robert
parents:
diff changeset
195 $setBoundary = preg_replace($remove3,'', $setBoundary);
a6b55ae70617 original
robert
parents:
diff changeset
196 $setBoundary2 = str_replace('<br />','', $setBoundary);
a6b55ae70617 original
robert
parents:
diff changeset
197 //remove all extra crap;
a6b55ae70617 original
robert
parents:
diff changeset
198 $setBoundary3 = str_replace('</td>','BOTTOM', $setBoundary2);
a6b55ae70617 original
robert
parents:
diff changeset
199 //replace </td> with BOTTOM
a6b55ae70617 original
robert
parents:
diff changeset
200
a6b55ae70617 original
robert
parents:
diff changeset
201 if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews))
a6b55ae70617 original
robert
parents:
diff changeset
202 {
a6b55ae70617 original
robert
parents:
diff changeset
203 $reviewContents = $reviews[1];
a6b55ae70617 original
robert
parents:
diff changeset
204 //print_r($reviewContents);
a6b55ae70617 original
robert
parents:
diff changeset
205 $review1 = trim($reviewContents[0]);
a6b55ae70617 original
robert
parents:
diff changeset
206 $review1 = str_replace("\n", "", $review1);
a6b55ae70617 original
robert
parents:
diff changeset
207 $review1 = str_replace("\r", "", $review1);
a6b55ae70617 original
robert
parents:
diff changeset
208 if (isset($reviewContents[1])) {
a6b55ae70617 original
robert
parents:
diff changeset
209 $review2 = trim($reviewContents[1]);
a6b55ae70617 original
robert
parents:
diff changeset
210 $review2 = str_replace("\n", "", $review2);
a6b55ae70617 original
robert
parents:
diff changeset
211 $review2 = str_replace("\r", "", $review2);
a6b55ae70617 original
robert
parents:
diff changeset
212 }
a6b55ae70617 original
robert
parents:
diff changeset
213 else {
a6b55ae70617 original
robert
parents:
diff changeset
214 $review2 = "";
a6b55ae70617 original
robert
parents:
diff changeset
215 }
a6b55ae70617 original
robert
parents:
diff changeset
216 if (isset($reviewContents[2])) {
a6b55ae70617 original
robert
parents:
diff changeset
217 $review3 = trim($reviewContents[2]);
a6b55ae70617 original
robert
parents:
diff changeset
218 $review3 = str_replace("\n", "", $review3);
a6b55ae70617 original
robert
parents:
diff changeset
219 $review3 = str_replace("\r", "", $review3);
a6b55ae70617 original
robert
parents:
diff changeset
220 }
a6b55ae70617 original
robert
parents:
diff changeset
221 else {
a6b55ae70617 original
robert
parents:
diff changeset
222 $review3 = "";
a6b55ae70617 original
robert
parents:
diff changeset
223 }
a6b55ae70617 original
robert
parents:
diff changeset
224 }
a6b55ae70617 original
robert
parents:
diff changeset
225 else
a6b55ae70617 original
robert
parents:
diff changeset
226 {
a6b55ae70617 original
robert
parents:
diff changeset
227 $review1 = "";
a6b55ae70617 original
robert
parents:
diff changeset
228 $review2 = "";
a6b55ae70617 original
robert
parents:
diff changeset
229 $review3 = "";
a6b55ae70617 original
robert
parents:
diff changeset
230 //echo "EPIC FAIL";
a6b55ae70617 original
robert
parents:
diff changeset
231 }
a6b55ae70617 original
robert
parents:
diff changeset
232
a6b55ae70617 original
robert
parents:
diff changeset
233 unset($xml->Items->Item->CustomerReviews);
a6b55ae70617 original
robert
parents:
diff changeset
234 $xdoc = new DomDocument;
a6b55ae70617 original
robert
parents:
diff changeset
235 $xdoc->loadXML($xml->asXML());
a6b55ae70617 original
robert
parents:
diff changeset
236
a6b55ae70617 original
robert
parents:
diff changeset
237 $cReviews = $xdoc ->createElement('CustomerReviews');
a6b55ae70617 original
robert
parents:
diff changeset
238 $cReviewHolder = $xdoc ->createElement('Review');
a6b55ae70617 original
robert
parents:
diff changeset
239 $cReview = $xdoc ->createElement('Content');
a6b55ae70617 original
robert
parents:
diff changeset
240 $cReviewHolder2 = $xdoc ->createElement('Review');
a6b55ae70617 original
robert
parents:
diff changeset
241 $cReview2 = $xdoc ->createElement('Content');
a6b55ae70617 original
robert
parents:
diff changeset
242 $cReviewHolder3 = $xdoc ->createElement('Review');
a6b55ae70617 original
robert
parents:
diff changeset
243 $cReview3 = $xdoc ->createElement('Content');
a6b55ae70617 original
robert
parents:
diff changeset
244
a6b55ae70617 original
robert
parents:
diff changeset
245 $txtNode = $xdoc ->createTextNode ($review1);
a6b55ae70617 original
robert
parents:
diff changeset
246 $cReview -> appendChild($txtNode);
a6b55ae70617 original
robert
parents:
diff changeset
247
a6b55ae70617 original
robert
parents:
diff changeset
248 $txtNode2 = $xdoc ->createTextNode ($review2);
a6b55ae70617 original
robert
parents:
diff changeset
249 $cReview2 -> appendChild($txtNode2);
a6b55ae70617 original
robert
parents:
diff changeset
250
a6b55ae70617 original
robert
parents:
diff changeset
251 $txtNode3 = $xdoc ->createTextNode ($review3);
a6b55ae70617 original
robert
parents:
diff changeset
252 $cReview3 -> appendChild($txtNode3);
a6b55ae70617 original
robert
parents:
diff changeset
253
a6b55ae70617 original
robert
parents:
diff changeset
254 $cReviewHolder -> appendChild($cReview);
a6b55ae70617 original
robert
parents:
diff changeset
255 $cReviewHolder2 -> appendChild($cReview2);
a6b55ae70617 original
robert
parents:
diff changeset
256 $cReviewHolder3 -> appendChild($cReview3);
a6b55ae70617 original
robert
parents:
diff changeset
257
a6b55ae70617 original
robert
parents:
diff changeset
258 $cReviews -> appendChild($cReviewHolder);
a6b55ae70617 original
robert
parents:
diff changeset
259 $cReviews -> appendChild($cReviewHolder2);
a6b55ae70617 original
robert
parents:
diff changeset
260 $cReviews -> appendChild($cReviewHolder3);
a6b55ae70617 original
robert
parents:
diff changeset
261
a6b55ae70617 original
robert
parents:
diff changeset
262 $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews);
a6b55ae70617 original
robert
parents:
diff changeset
263 $newXML = simplexml_import_dom($xdoc);
a6b55ae70617 original
robert
parents:
diff changeset
264 $output = $newXML->asXml();
a6b55ae70617 original
robert
parents:
diff changeset
265 }
a6b55ae70617 original
robert
parents:
diff changeset
266
a6b55ae70617 original
robert
parents:
diff changeset
267 switch($locale){
a6b55ae70617 original
robert
parents:
diff changeset
268 case "us":
a6b55ae70617 original
robert
parents:
diff changeset
269 $loc = 0;
a6b55ae70617 original
robert
parents:
diff changeset
270 break;
a6b55ae70617 original
robert
parents:
diff changeset
271 case "uk":
a6b55ae70617 original
robert
parents:
diff changeset
272 $loc = 1;
a6b55ae70617 original
robert
parents:
diff changeset
273 break;
a6b55ae70617 original
robert
parents:
diff changeset
274 case "ca":
a6b55ae70617 original
robert
parents:
diff changeset
275 $loc = 2;
a6b55ae70617 original
robert
parents:
diff changeset
276 break;
a6b55ae70617 original
robert
parents:
diff changeset
277 case "de":
a6b55ae70617 original
robert
parents:
diff changeset
278 $loc = 3;
a6b55ae70617 original
robert
parents:
diff changeset
279 break;
a6b55ae70617 original
robert
parents:
diff changeset
280 case "fr":
a6b55ae70617 original
robert
parents:
diff changeset
281 $loc = 4;
a6b55ae70617 original
robert
parents:
diff changeset
282 break;
a6b55ae70617 original
robert
parents:
diff changeset
283 };
a6b55ae70617 original
robert
parents:
diff changeset
284
a6b55ae70617 original
robert
parents:
diff changeset
285 $errorCode = $xml->Error->Code;
a6b55ae70617 original
robert
parents:
diff changeset
286 //echo $errorCode;
a6b55ae70617 original
robert
parents:
diff changeset
287
a6b55ae70617 original
robert
parents:
diff changeset
288 if($errorCode != "AccountLimitExceeded")
a6b55ae70617 original
robert
parents:
diff changeset
289 {
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
290 if($go == 1) {
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
291 $item = $xml->Items->Item[0];
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
292 if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
293 $title = $item->ItemAttributes->Title; }
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
294 else { $title = "[no title]"; };
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
295 file_put_contents('/var/ywww/debug/phpDebug',"win: ".
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
296 $title."\n",
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
297 FILE_APPEND);
4
a6b55ae70617 original
robert
parents:
diff changeset
298 return $output;
5
55445b456ad0 short-circuit error response handling, add debugging
robert
parents: 4
diff changeset
299 }
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
300 else
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
301 {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
302 if ($xml->Items->Item) {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
303 $title = $xml->Items->Item[0]->ItemAttributes->Title;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
304 $author = $xml->Items->Item[0]->ItemAttributes->Author;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
305 $binding = $xml->Items->Item[0]->ItemAttributes->Binding;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
306 $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
307 if($dewey == "")
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
308 $dewey = "null";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
309 $imageURL = $xml->Items->Item[0]->MediumImage->URL;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
310 $salesRank = $xml->Items->Item[0]->SalesRank;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
311 $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
312 $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
313 }
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
314 else {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
315 $title = $salesRank = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
316 $dewey = "null";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
317 }
4
a6b55ae70617 original
robert
parents:
diff changeset
318
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
319 $genreID = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
320 $genre = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
321 $genArr = array();
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
322
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
323 if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
324 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
325 //sexy recursive function
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
326 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
4
a6b55ae70617 original
robert
parents:
diff changeset
327
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
328 if($genre != "")
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
329 $genArr[strval($genreID)] = strval($genre);
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
330 //$genArr[$i] = array(strval($genreID) => strval($genre));
4
a6b55ae70617 original
robert
parents:
diff changeset
331
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
332 //echo $genre;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
333 //echo $genreID;
4
a6b55ae70617 original
robert
parents:
diff changeset
334
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
335 $genre = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
336 $genreID = "";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
337 }
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
338 }
4
a6b55ae70617 original
robert
parents:
diff changeset
339
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
340 $g1 = "null";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
341 $g2 = "null";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
342 $g3 = "null";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
343 $loop = 1;
4
a6b55ae70617 original
robert
parents:
diff changeset
344
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
345 foreach ($genArr as $key => $value) {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
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
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
351 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
352 //echo $queryG;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
353 include "../../private/db.php";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
354 $resG = mysqli_query($link, $queryG);
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
355 mysqli_close($link);
4
a6b55ae70617 original
robert
parents:
diff changeset
356
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
357 switch ($loop) {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
358 case 1:
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
359 $g1 = $key;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
360 break;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
361 case 2:
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
362 $g2 = $key;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
363 break;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
364 case 3:
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
365 $g3 = $key;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
366 break;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
367 }
4
a6b55ae70617 original
robert
parents:
diff changeset
368
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
369 $loop++;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
370 }
4
a6b55ae70617 original
robert
parents:
diff changeset
371
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
372 if($salesRank == "")
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
373 $salesRank = "null";
4
a6b55ae70617 original
robert
parents:
diff changeset
374
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
375 $title = strtr($title, '"', "'");
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
376 include "../../private/db.php";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
377 $review1 = mysqli_real_escape_string($link,$review1);
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
378 $review2 = mysqli_real_escape_string($link,$review2);
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
379 $review3 = mysqli_real_escape_string($link,$review3);
4
a6b55ae70617 original
robert
parents:
diff changeset
380
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
381 if($title != "")
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
382 {
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
383 $queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
384 //echo $queryInsert;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
385 $queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")";
4
a6b55ae70617 original
robert
parents:
diff changeset
386
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
387 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
388 if($review1 != "" && $review2 != "" && $review3 != "")
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
389 $resG = mysqli_query($link, $queryInsertReviews) or exit( mysqli_error( $link ));
4
a6b55ae70617 original
robert
parents:
diff changeset
390
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
391 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
392 }
4
a6b55ae70617 original
robert
parents:
diff changeset
393
19
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
394 echo $output;
84a412b8122c try to protect against a range of missing info
Charlie Root
parents: 18
diff changeset
395 }
4
a6b55ae70617 original
robert
parents:
diff changeset
396 }
a6b55ae70617 original
robert
parents:
diff changeset
397 else
a6b55ae70617 original
robert
parents:
diff changeset
398 {
a6b55ae70617 original
robert
parents:
diff changeset
399 //look up info from db
a6b55ae70617 original
robert
parents:
diff changeset
400 include "../../private/db.php";
a6b55ae70617 original
robert
parents:
diff changeset
401 $query = "CALL b_getBookInfo('$searchparameterdata', $loc)";
a6b55ae70617 original
robert
parents:
diff changeset
402 //echo $query;
a6b55ae70617 original
robert
parents:
diff changeset
403 $res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
a6b55ae70617 original
robert
parents:
diff changeset
404
a6b55ae70617 original
robert
parents:
diff changeset
405 $output = "";
a6b55ae70617 original
robert
parents:
diff changeset
406 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
a6b55ae70617 original
robert
parents:
diff changeset
407 $output .= "<Details>";
a6b55ae70617 original
robert
parents:
diff changeset
408 if ( mysqli_num_rows( $res ) > 0 )
a6b55ae70617 original
robert
parents:
diff changeset
409 {
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
412 $output .= "<ASIN>" . $searchparameterdata . "</ASIN>";
a6b55ae70617 original
robert
parents:
diff changeset
413 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>";
a6b55ae70617 original
robert
parents:
diff changeset
414 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>";
a6b55ae70617 original
robert
parents:
diff changeset
415 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>";
a6b55ae70617 original
robert
parents:
diff changeset
416 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>";
a6b55ae70617 original
robert
parents:
diff changeset
417 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>";
a6b55ae70617 original
robert
parents:
diff changeset
418 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>";
a6b55ae70617 original
robert
parents:
diff changeset
419 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>";
a6b55ae70617 original
robert
parents:
diff changeset
420 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>";
a6b55ae70617 original
robert
parents:
diff changeset
421 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>";
a6b55ae70617 original
robert
parents:
diff changeset
422 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>";
a6b55ae70617 original
robert
parents:
diff changeset
423 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>";
a6b55ae70617 original
robert
parents:
diff changeset
424 $output .= "<ProductGroup>Book</ProductGroup>";
a6b55ae70617 original
robert
parents:
diff changeset
425 $output .= "<Error>AccountLimitExceeded</Error>";
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
431 $output .= "</Details>";
a6b55ae70617 original
robert
parents:
diff changeset
432 echo $output;
a6b55ae70617 original
robert
parents:
diff changeset
433 }
a6b55ae70617 original
robert
parents:
diff changeset
434 }
a6b55ae70617 original
robert
parents:
diff changeset
435
a6b55ae70617 original
robert
parents:
diff changeset
436 function findGenre($browseNode, &$ID, &$gen)
a6b55ae70617 original
robert
parents:
diff changeset
437 {
a6b55ae70617 original
robert
parents:
diff changeset
438 if($browseNode->Name == "Subjects")
a6b55ae70617 original
robert
parents:
diff changeset
439 {
a6b55ae70617 original
robert
parents:
diff changeset
440 return true;
a6b55ae70617 original
robert
parents:
diff changeset
441 }
a6b55ae70617 original
robert
parents:
diff changeset
442 else
a6b55ae70617 original
robert
parents:
diff changeset
443 {
a6b55ae70617 original
robert
parents:
diff changeset
444 if($browseNode->Ancestors->BrowseNode)
a6b55ae70617 original
robert
parents:
diff changeset
445 {
a6b55ae70617 original
robert
parents:
diff changeset
446 if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true)
a6b55ae70617 original
robert
parents:
diff changeset
447 {
a6b55ae70617 original
robert
parents:
diff changeset
448 $gen = $browseNode->Name;
a6b55ae70617 original
robert
parents:
diff changeset
449 $ID = $browseNode->BrowseNodeId;
a6b55ae70617 original
robert
parents:
diff changeset
450 }
a6b55ae70617 original
robert
parents:
diff changeset
451 }
a6b55ae70617 original
robert
parents:
diff changeset
452 return false;
a6b55ae70617 original
robert
parents:
diff changeset
453 }
a6b55ae70617 original
robert
parents:
diff changeset
454 }
a6b55ae70617 original
robert
parents:
diff changeset
455
a6b55ae70617 original
robert
parents:
diff changeset
456 if(!isset($ret))
a6b55ae70617 original
robert
parents:
diff changeset
457 {
a6b55ae70617 original
robert
parents:
diff changeset
458 include "aws_signed_request.php";
a6b55ae70617 original
robert
parents:
diff changeset
459 getAmazonDet('default',0,'us'); //will get overwritten
a6b55ae70617 original
robert
parents:
diff changeset
460 }
a6b55ae70617 original
robert
parents:
diff changeset
461 /*Caught oneSimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
462 (
a6b55ae70617 original
robert
parents:
diff changeset
463 [OperationRequest] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
464 (
a6b55ae70617 original
robert
parents:
diff changeset
465 [RequestId] => d2eaacba-2411-44e7-b268-f23a20167330
a6b55ae70617 original
robert
parents:
diff changeset
466 [Arguments] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
467 (
a6b55ae70617 original
robert
parents:
diff changeset
468 [Argument] => Array
a6b55ae70617 original
robert
parents:
diff changeset
469 (
a6b55ae70617 original
robert
parents:
diff changeset
470 [0] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
471 (
a6b55ae70617 original
robert
parents:
diff changeset
472 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
473 (
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
476 )
a6b55ae70617 original
robert
parents:
diff changeset
477
a6b55ae70617 original
robert
parents:
diff changeset
478 )
a6b55ae70617 original
robert
parents:
diff changeset
479
a6b55ae70617 original
robert
parents:
diff changeset
480 [1] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
481 (
a6b55ae70617 original
robert
parents:
diff changeset
482 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
483 (
a6b55ae70617 original
robert
parents:
diff changeset
484 [Name] => AssociateTag
a6b55ae70617 original
robert
parents:
diff changeset
485 [Value] => bookwhack-21
a6b55ae70617 original
robert
parents:
diff changeset
486 )
a6b55ae70617 original
robert
parents:
diff changeset
487
a6b55ae70617 original
robert
parents:
diff changeset
488 )
a6b55ae70617 original
robert
parents:
diff changeset
489
a6b55ae70617 original
robert
parents:
diff changeset
490 [2] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
491 (
a6b55ae70617 original
robert
parents:
diff changeset
492 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
493 (
a6b55ae70617 original
robert
parents:
diff changeset
494 [Name] => ItemId
a6b55ae70617 original
robert
parents:
diff changeset
495 [Value] => B004Q3Q3Y4
a6b55ae70617 original
robert
parents:
diff changeset
496 )
a6b55ae70617 original
robert
parents:
diff changeset
497
a6b55ae70617 original
robert
parents:
diff changeset
498 )
a6b55ae70617 original
robert
parents:
diff changeset
499
a6b55ae70617 original
robert
parents:
diff changeset
500 [3] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
501 (
a6b55ae70617 original
robert
parents:
diff changeset
502 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
503 (
a6b55ae70617 original
robert
parents:
diff changeset
504 [Name] => ItemPage
a6b55ae70617 original
robert
parents:
diff changeset
505 [Value] => 1
a6b55ae70617 original
robert
parents:
diff changeset
506 )
a6b55ae70617 original
robert
parents:
diff changeset
507
a6b55ae70617 original
robert
parents:
diff changeset
508 )
a6b55ae70617 original
robert
parents:
diff changeset
509
a6b55ae70617 original
robert
parents:
diff changeset
510 [4] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
511 (
a6b55ae70617 original
robert
parents:
diff changeset
512 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
513 (
a6b55ae70617 original
robert
parents:
diff changeset
514 [Name] => Operation
a6b55ae70617 original
robert
parents:
diff changeset
515 [Value] => ItemLookup
a6b55ae70617 original
robert
parents:
diff changeset
516 )
a6b55ae70617 original
robert
parents:
diff changeset
517
a6b55ae70617 original
robert
parents:
diff changeset
518 )
a6b55ae70617 original
robert
parents:
diff changeset
519
a6b55ae70617 original
robert
parents:
diff changeset
520 [5] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
521 (
a6b55ae70617 original
robert
parents:
diff changeset
522 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
523 (
a6b55ae70617 original
robert
parents:
diff changeset
524 [Name] => ResponseGroup
a6b55ae70617 original
robert
parents:
diff changeset
525 [Value] => ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes
a6b55ae70617 original
robert
parents:
diff changeset
526 )
a6b55ae70617 original
robert
parents:
diff changeset
527
a6b55ae70617 original
robert
parents:
diff changeset
528 )
a6b55ae70617 original
robert
parents:
diff changeset
529
a6b55ae70617 original
robert
parents:
diff changeset
530 [6] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
531 (
a6b55ae70617 original
robert
parents:
diff changeset
532 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
533 (
a6b55ae70617 original
robert
parents:
diff changeset
534 [Name] => ReviewSort
a6b55ae70617 original
robert
parents:
diff changeset
535 [Value] => -HelpfulVotes
a6b55ae70617 original
robert
parents:
diff changeset
536 )
a6b55ae70617 original
robert
parents:
diff changeset
537
a6b55ae70617 original
robert
parents:
diff changeset
538 )
a6b55ae70617 original
robert
parents:
diff changeset
539
a6b55ae70617 original
robert
parents:
diff changeset
540 [7] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
541 (
a6b55ae70617 original
robert
parents:
diff changeset
542 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
543 (
a6b55ae70617 original
robert
parents:
diff changeset
544 [Name] => Service
a6b55ae70617 original
robert
parents:
diff changeset
545 [Value] => AWSECommerceService
a6b55ae70617 original
robert
parents:
diff changeset
546 )
a6b55ae70617 original
robert
parents:
diff changeset
547
a6b55ae70617 original
robert
parents:
diff changeset
548 )
a6b55ae70617 original
robert
parents:
diff changeset
549
a6b55ae70617 original
robert
parents:
diff changeset
550 [8] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
551 (
a6b55ae70617 original
robert
parents:
diff changeset
552 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
553 (
a6b55ae70617 original
robert
parents:
diff changeset
554 [Name] => Timestamp
a6b55ae70617 original
robert
parents:
diff changeset
555 [Value] => 2016-12-15T23:12:34Z
a6b55ae70617 original
robert
parents:
diff changeset
556 )
a6b55ae70617 original
robert
parents:
diff changeset
557
a6b55ae70617 original
robert
parents:
diff changeset
558 )
a6b55ae70617 original
robert
parents:
diff changeset
559
a6b55ae70617 original
robert
parents:
diff changeset
560 [9] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
561 (
a6b55ae70617 original
robert
parents:
diff changeset
562 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
563 (
a6b55ae70617 original
robert
parents:
diff changeset
564 [Name] => Version
a6b55ae70617 original
robert
parents:
diff changeset
565 [Value] => 2011-08-01
a6b55ae70617 original
robert
parents:
diff changeset
566 )
a6b55ae70617 original
robert
parents:
diff changeset
567
a6b55ae70617 original
robert
parents:
diff changeset
568 )
a6b55ae70617 original
robert
parents:
diff changeset
569
a6b55ae70617 original
robert
parents:
diff changeset
570 [10] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
571 (
a6b55ae70617 original
robert
parents:
diff changeset
572 [@attributes] => Array
a6b55ae70617 original
robert
parents:
diff changeset
573 (
a6b55ae70617 original
robert
parents:
diff changeset
574 [Name] => Signature
a6b55ae70617 original
robert
parents:
diff changeset
575 [Value] => SUXfFZHQ74Joc+WDLx87uzemTdtHijNohykqafJXYKQ=
a6b55ae70617 original
robert
parents:
diff changeset
576 )
a6b55ae70617 original
robert
parents:
diff changeset
577
a6b55ae70617 original
robert
parents:
diff changeset
578 )
a6b55ae70617 original
robert
parents:
diff changeset
579
a6b55ae70617 original
robert
parents:
diff changeset
580 )
a6b55ae70617 original
robert
parents:
diff changeset
581
a6b55ae70617 original
robert
parents:
diff changeset
582 )
a6b55ae70617 original
robert
parents:
diff changeset
583
a6b55ae70617 original
robert
parents:
diff changeset
584 [RequestProcessingTime] => 0.3518217620000000
a6b55ae70617 original
robert
parents:
diff changeset
585 )
a6b55ae70617 original
robert
parents:
diff changeset
586
a6b55ae70617 original
robert
parents:
diff changeset
587 [Items] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
588 (
a6b55ae70617 original
robert
parents:
diff changeset
589 [Request] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
590 (
a6b55ae70617 original
robert
parents:
diff changeset
591 [IsValid] => True
a6b55ae70617 original
robert
parents:
diff changeset
592 [ItemLookupRequest] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
593 (
a6b55ae70617 original
robert
parents:
diff changeset
594 [IdType] => ASIN
a6b55ae70617 original
robert
parents:
diff changeset
595 [ItemId] => B004Q3Q3Y4
a6b55ae70617 original
robert
parents:
diff changeset
596 [ResponseGroup] => Array
a6b55ae70617 original
robert
parents:
diff changeset
597 (
a6b55ae70617 original
robert
parents:
diff changeset
598 [0] => ItemAttributes
a6b55ae70617 original
robert
parents:
diff changeset
599 [1] => Reviews
a6b55ae70617 original
robert
parents:
diff changeset
600 [2] => EditorialReview
a6b55ae70617 original
robert
parents:
diff changeset
601 [3] => OfferSummary
a6b55ae70617 original
robert
parents:
diff changeset
602 [4] => Offers
a6b55ae70617 original
robert
parents:
diff changeset
603 [5] => Images
a6b55ae70617 original
robert
parents:
diff changeset
604 [6] => AlternateVersions
a6b55ae70617 original
robert
parents:
diff changeset
605 [7] => SalesRank
a6b55ae70617 original
robert
parents:
diff changeset
606 [8] => BrowseNodes
a6b55ae70617 original
robert
parents:
diff changeset
607 )
a6b55ae70617 original
robert
parents:
diff changeset
608
a6b55ae70617 original
robert
parents:
diff changeset
609 [VariationPage] => All
a6b55ae70617 original
robert
parents:
diff changeset
610 )
a6b55ae70617 original
robert
parents:
diff changeset
611
a6b55ae70617 original
robert
parents:
diff changeset
612 [Errors] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
613 (
a6b55ae70617 original
robert
parents:
diff changeset
614 [Error] => SimpleXMLElement Object
a6b55ae70617 original
robert
parents:
diff changeset
615 (
a6b55ae70617 original
robert
parents:
diff changeset
616 [Code] => AWS.InvalidParameterValue
a6b55ae70617 original
robert
parents:
diff changeset
617 [Message] => B004Q3Q3Y4 is not a valid value for ItemId. Please change this value and retry your request.
a6b55ae70617 original
robert
parents:
diff changeset
618 )
a6b55ae70617 original
robert
parents:
diff changeset
619
a6b55ae70617 original
robert
parents:
diff changeset
620 )
a6b55ae70617 original
robert
parents:
diff changeset
621
a6b55ae70617 original
robert
parents:
diff changeset
622 )
a6b55ae70617 original
robert
parents:
diff changeset
623
a6b55ae70617 original
robert
parents:
diff changeset
624 )
a6b55ae70617 original
robert
parents:
diff changeset
625
a6b55ae70617 original
robert
parents:
diff changeset
626 )
a6b55ae70617 original
robert
parents:
diff changeset
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
a6b55ae70617 original
robert
parents:
diff changeset
629 ?>