# HG changeset patch # User Charlie Root # Date 1546777023 18000 # Node ID 38d20961150887195393fb0d05fc798ac35392f1 # Parent dbc006408d2b450347ee7a5be46117f8d7560167 change includes to assume (contra previos ASSUMES) that we have .user.ini which adds /var/test to include_path diff -r dbc006408d2b -r 38d209611508 .user.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.user.ini Sun Jan 06 07:17:03 2019 -0500 @@ -0,0 +1,1 @@ +include_path = ".:/var/test:/usr/share/php" diff -r dbc006408d2b -r 38d209611508 index.php --- a/index.php Sat Jan 05 18:00:10 2019 -0500 +++ b/index.php Sun Jan 06 07:17:03 2019 -0500 @@ -1,5 +1,5 @@ Name == "Subjects") @@ -61,7 +61,7 @@ $output .= ""; $proceed = true; - include "../../../private/db.php"; + include "private/db.php"; $query = "CALL b_getBookInfo('$isbn', $loc)"; //select Timestamp,Title,Author,Binding,DeweyDecimal,ImageURL,SalesRank,PublicationDate,Publisher,Genre1,Genre2,Genre3 from books where ISBN = '$isbn'"; @@ -107,7 +107,7 @@ if($proceed == true) { include "aws_signed_request.php"; - include_once "../../xml/doAmazonRequest.inc"; + include_once "../../xml/doAmazonRequest.php"; dl("nbd proceeding: $isbn\n"); //book does not exist already so look up all the info from browse nodes.... @@ -155,7 +155,7 @@ dl("Caught one bd: $isbn\n"); dl(print_r($out, TRUE)."\n"); } ); - include "db.php"; + include "private/db.php"; $title=""; $author=""; diff -r dbc006408d2b -r 38d209611508 us/index.php --- a/us/index.php Sat Jan 05 18:00:10 2019 -0500 +++ b/us/index.php Sun Jan 06 07:17:03 2019 -0500 @@ -1,5 +1,5 @@ 'en', //what language to render the page in diff -r dbc006408d2b -r 38d209611508 xml/doAmazonRequest.inc --- a/xml/doAmazonRequest.inc Sat Jan 05 18:00:10 2019 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -$d) { - $file_data.='&'.$i.'='.$d; - } - $gotit=0; - $url=aws_signed_request($ext,$parameters,$public_key,$private_key); - //dl("search: $ext $public_key $private_key\n$url\n".print_r($parameters,TRUE)."\n"); - for ($i=1; $i<=$try; $i++) { - $crl = curl_init(); - $timeout = 5; - curl_setopt ($crl, CURLOPT_URL,$url); - curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); - curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); - $semaphore = new SyncSemaphore("Amazon"); - $gotit = $semaphore->lock(1000); - if (!$gotit) { - dl("Got it: ".(int)$gotit." $requestIP $dbl\n"); - $gotit=$semaphore->lock(1000); - dl("Got it: ".(int)$gotit." $requestIP $dbl"."a\n"); - } - $output = curl_exec($crl); - //dl("nai2: ".strlen($output)."\n"); - - curl_close($crl); - usleep(500000); - if ($gotit) { - $semaphore->unlock(); - } - else { - dl("W/o lock for $requestIP $dbl"."b\n"); - } - $mm=array(); - $xml = new SimpleXMLElement($output); - if (preg_match("//",$output,$mm)) { - $resName=$xml->getName(); - $code=$xml->Error->Code; - if ($code) { - $message=$xml->Error->Message; - } - else { - $code=$xml->Items->Request->Errors->Error->Code; - $message=$xml->Items->Request->Errors->Error->Message; - } - dl("Losing $i: $dbl ". - $mm[0].", $resName, $code, $requestIP, $requestURI\n"); - if ($code!='RequestThrottled') { - dl("message: $message\n"); - if ($code=='AWS.InvalidParameterValue' && strpos($message,"for ItemId.")>0) { - // Check for common problem and try to fix... - $spd=$parameters['ItemId']; - if (strpos($spd,'/')>0) { - $isbnMaybe=substr($spd,0,strpos($spd,'/')); - $parameters['ItemId']=$isbnMaybe; - if (isset($parameters['Keywords'])) { - $parameters['Keywords']=urlencode($isbnMaybe); - } - dl("retrying with $isbnMaybe\n"); - return doAmazonRequest($ext,$parameters,$try,$dbl); - } - } - if ($code=="") { - dl("error elt:\n$output\n"); - } - throw new Exception($code); - } - } - else { - if ($wantXML) { - return $xml; - } - else { - //dl("returning ".strlen($output)."\n"); - return $output; - } - } - usleep(100000*$i); // Try to reduce throttling until we get a - // principled solution in place - } - throw new Exception("ThrottledRepeatedly"); -} -?> diff -r dbc006408d2b -r 38d209611508 xml/doAmazonRequest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/doAmazonRequest.php Sun Jan 06 07:17:03 2019 -0500 @@ -0,0 +1,94 @@ +$d) { + $file_data.='&'.$i.'='.$d; + } + $gotit=0; + $url=aws_signed_request($ext,$parameters,$public_key,$private_key); + //dl("search: $ext $public_key $private_key\n$url\n".print_r($parameters,TRUE)."\n"); + for ($i=1; $i<=$try; $i++) { + $crl = curl_init(); + $timeout = 5; + curl_setopt ($crl, CURLOPT_URL,$url); + curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); + curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); + $semaphore = new SyncSemaphore("Amazon"); + $gotit = $semaphore->lock(1000); + if (!$gotit) { + dl("Got it: ".(int)$gotit." $requestIP $dbl\n"); + $gotit=$semaphore->lock(1000); + dl("Got it: ".(int)$gotit." $requestIP $dbl"."a\n"); + } + $output = curl_exec($crl); + //dl("nai2: ".strlen($output)."\n"); + + curl_close($crl); + usleep(500000); + if ($gotit) { + $semaphore->unlock(); + } + else { + dl("W/o lock for $requestIP $dbl"."b\n"); + } + $mm=array(); + $xml = new SimpleXMLElement($output); + if (preg_match("//",$output,$mm)) { + $resName=$xml->getName(); + $code=$xml->Error->Code; + if ($code) { + $message=$xml->Error->Message; + } + else { + $code=$xml->Items->Request->Errors->Error->Code; + $message=$xml->Items->Request->Errors->Error->Message; + } + dl("Losing $i: $dbl ". + $mm[0].", $resName, $code, $requestIP, $requestURI\n"); + if ($code!='RequestThrottled') { + dl("message: $message\n"); + if ($code=='AWS.InvalidParameterValue' && strpos($message,"for ItemId.")>0) { + // Check for common problem and try to fix... + $spd=$parameters['ItemId']; + if (strpos($spd,'/')>0) { + $isbnMaybe=substr($spd,0,strpos($spd,'/')); + $parameters['ItemId']=$isbnMaybe; + if (isset($parameters['Keywords'])) { + $parameters['Keywords']=urlencode($isbnMaybe); + } + dl("retrying with $isbnMaybe\n"); + return doAmazonRequest($ext,$parameters,$try,$dbl); + } + } + if ($code=="") { + dl("error elt:\n$output\n"); + } + throw new Exception($code); + } + } + else { + if ($wantXML) { + return $xml; + } + else { + //dl("returning ".strlen($output)."\n"); + return $output; + } + } + usleep(100000*$i); // Try to reduce throttling until we get a + // principled solution in place + } + throw new Exception("ThrottledRepeatedly"); +} +?> diff -r dbc006408d2b -r 38d209611508 xml/getAmazonInfo.php --- a/xml/getAmazonInfo.php Sat Jan 05 18:00:10 2019 -0500 +++ b/xml/getAmazonInfo.php Sun Jan 06 07:17:03 2019 -0500 @@ -1,6 +1,6 @@