# HG changeset patch # User Robert Boland # Date 1487338820 0 # Node ID 1dfe64e365a01f42f6a13e7a9a451539d397a0be # Parent 077b0a0a3e6df4b684efd4fd2155bb7aedbc464d a bit more debugging/bomb-proofing diff -r 077b0a0a3e6d -r 1dfe64e365a0 us/index.php --- a/us/index.php Thu Feb 16 22:29:02 2017 +0000 +++ b/us/index.php Fri Feb 17 13:40:20 2017 +0000 @@ -150,32 +150,56 @@ $recommended = ""; $linkedRecommended = ""; for($i=0;$iisbn);$i++){ - $linkedISBN = $xml->isbn[$i]; - include "../../private/db.php"; - $query = "CALL b_getBookInfo('$linkedISBN', $countryCode)"; - //echo $query; - $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); - if ( mysqli_num_rows( $res ) > 0 ) - { - $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); - $titleL = $rows["Title"]; - $authorL = $rows["Author"]; - mysqli_close($link); - } - else - { - $bookLDetails = getAmazonDet($linkedISBN,1,'us'); - $bookLXML = new SimpleXMLElement($bookLDetails); - $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; - $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + $linkedISBN = $xml->isbn[$i]; + include "../../private/db.php"; + $query = "CALL b_getBookInfo('$linkedISBN', $countryCode)"; + //echo $query; + $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); + set_error_handler(function () { + global $bookLDetails, $linkedISBN; + file_put_contents('/var/ywww/debug/phpDebug', + "Caught other one?: ".$linkedISBN, + FILE_APPEND); + //file_put_contents('/var/ywww/debug/phpDebug', + // print_r($bookLDetails, TRUE)."\n", + // FILE_APPEND); + } ); + if ( mysqli_num_rows( $res ) > 0 ) + { + $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); + $titleL = $rows["Title"]; + $authorL = $rows["Author"]; + mysqli_close($link); + } + else + { + $bookLDetails = getAmazonDet($linkedISBN,1,'us'); + $bookLXML = new SimpleXMLElement($bookLDetails); + // HST added this + if (preg_match("",$bookLDetails)) { + $resName=$bookLXML->getName(); + $code=$bookLXML->Error->Code; + file_put_contents('/var/ywww/debug/phpDebug',"Losing 2: $resName, ". + $code."\n",FILE_APPEND); + if ($code=='RequestThrottled') { + usleep(200000); // Try to reduce throttling until we get a + // principled solution in place } - if($titleL != "") - { - $recommended .= " $titleL by $authorL,"; - $underAuthor = str_replace(" ","_",$authorL); - $underTitle = str_replace(" ","_",$titleL); - $linkedRecommended .= "$titleL by $authorL, "; - } + $titleL = ""; + } + else { + $titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title; + $authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author; + } + } + restore_error_handler(); + if($titleL != "") + { + $recommended .= " $titleL by $authorL,"; + $underAuthor = str_replace(" ","_",$authorL); + $underTitle = str_replace(" ","_",$titleL); + $linkedRecommended .= "$titleL by $authorL, "; + } } $vote = "Vote on these recommendations!"; diff -r 077b0a0a3e6d -r 1dfe64e365a0 xml/getAmazonInfo.php --- a/xml/getAmazonInfo.php Thu Feb 16 22:29:02 2017 +0000 +++ b/xml/getAmazonInfo.php Fri Feb 17 13:40:20 2017 +0000 @@ -118,7 +118,11 @@ $resName=$xml->getName(); $code=$xml->Error->Code; file_put_contents('/var/ywww/debug/phpDebug',"Losing: $resName, ". - $xml->Error->Code."\n",FILE_APPEND); + $code."\n",FILE_APPEND); + if ($code=='RequestThrottled') { + usleep(200000); // Try to reduce throttling until we get a + // principled solution in place + } } else { $xml = new SimpleXMLElement($output);