comparison us/index.php @ 7:1dfe64e365a0

a bit more debugging/bomb-proofing
author Robert Boland <robert@markup.co.uk>
date Fri, 17 Feb 2017 13:40:20 +0000
parents 077b0a0a3e6d
children 226f00d9f6f5
comparison
equal deleted inserted replaced
6:077b0a0a3e6d 7:1dfe64e365a0
148 $xml = new SimpleXMLElement($linkedBooks); 148 $xml = new SimpleXMLElement($linkedBooks);
149 149
150 $recommended = ""; 150 $recommended = "";
151 $linkedRecommended = ""; 151 $linkedRecommended = "";
152 for($i=0;$i<sizeof($xml->isbn);$i++){ 152 for($i=0;$i<sizeof($xml->isbn);$i++){
153 $linkedISBN = $xml->isbn[$i]; 153 $linkedISBN = $xml->isbn[$i];
154 include "../../private/db.php"; 154 include "../../private/db.php";
155 $query = "CALL b_getBookInfo('$linkedISBN', $countryCode)"; 155 $query = "CALL b_getBookInfo('$linkedISBN', $countryCode)";
156 //echo $query; 156 //echo $query;
157 $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); 157 $res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
158 if ( mysqli_num_rows( $res ) > 0 ) 158 set_error_handler(function () {
159 { 159 global $bookLDetails, $linkedISBN;
160 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); 160 file_put_contents('/var/ywww/debug/phpDebug',
161 $titleL = $rows["Title"]; 161 "Caught other one?: ".$linkedISBN,
162 $authorL = $rows["Author"]; 162 FILE_APPEND);
163 mysqli_close($link); 163 //file_put_contents('/var/ywww/debug/phpDebug',
164 } 164 // print_r($bookLDetails, TRUE)."\n",
165 else 165 // FILE_APPEND);
166 { 166 } );
167 $bookLDetails = getAmazonDet($linkedISBN,1,'us'); 167 if ( mysqli_num_rows( $res ) > 0 )
168 $bookLXML = new SimpleXMLElement($bookLDetails); 168 {
169 $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; 169 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
170 $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; 170 $titleL = $rows["Title"];
171 $authorL = $rows["Author"];
172 mysqli_close($link);
173 }
174 else
175 {
176 $bookLDetails = getAmazonDet($linkedISBN,1,'us');
177 $bookLXML = new SimpleXMLElement($bookLDetails);
178 // HST added this
179 if (preg_match("<Error>",$bookLDetails)) {
180 $resName=$bookLXML->getName();
181 $code=$bookLXML->Error->Code;
182 file_put_contents('/var/ywww/debug/phpDebug',"Losing 2: $resName, ".
183 $code."\n",FILE_APPEND);
184 if ($code=='RequestThrottled') {
185 usleep(200000); // Try to reduce throttling until we get a
186 // principled solution in place
171 } 187 }
172 if($titleL != "") 188 $titleL = "";
173 { 189 }
174 $recommended .= " $titleL by $authorL,"; 190 else {
175 $underAuthor = str_replace(" ","_",$authorL); 191 $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
176 $underTitle = str_replace(" ","_",$titleL); 192 $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
177 $linkedRecommended .= "<a href=\"http://www.YourNextRead.com/us/#!isbn=$linkedISBN/$underTitle" . "_by_$authorL\">$titleL by $authorL</a>, "; 193 }
178 } 194 }
195 restore_error_handler();
196 if($titleL != "")
197 {
198 $recommended .= " $titleL by $authorL,";
199 $underAuthor = str_replace(" ","_",$authorL);
200 $underTitle = str_replace(" ","_",$titleL);
201 $linkedRecommended .= "<a href=\"http://www.YourNextRead.com/us/#!isbn=$linkedISBN/$underTitle" . "_by_$authorL\">$titleL by $authorL</a>, ";
202 }
179 } 203 }
180 204
181 $vote = "Vote on these recommendations!"; 205 $vote = "Vote on these recommendations!";
182 206
183 echo "<META NAME=\"Description\" CONTENT=\"YourNextRead recommended books for $title by $author:$recommended $vote\">"; 207 echo "<META NAME=\"Description\" CONTENT=\"YourNextRead recommended books for $title by $author:$recommended $vote\">";