Mercurial > hg > ywww
changeset 44:38d209611508
change includes to assume (contra previos ASSUMES) that we have .user.ini which adds /var/test to include_path
author | Charlie Root |
---|---|
date | Sun, 06 Jan 2019 07:17:03 -0500 |
parents | dbc006408d2b |
children | 8bc395c87c6f |
files | .user.ini index.php php/read/getBookDetails.php us/index.php xml/amazonBookSearch.php xml/doAmazonRequest.inc xml/doAmazonRequest.php xml/getAmazonInfo.php |
diffstat | 8 files changed, 106 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- /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"
--- 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 @@ <?php -include_once "dlog.php"; +include_once "ywww/dlog.php"; if (isset($_SERVER["GEOIP_COUNTRY_CODE"])) { $country_code = $_SERVER["GEOIP_COUNTRY_CODE"];
--- a/php/read/getBookDetails.php Sat Jan 05 18:00:10 2019 -0500 +++ b/php/read/getBookDetails.php Sun Jan 06 07:17:03 2019 -0500 @@ -1,7 +1,7 @@ <?php -include_once "dlog.php"; +include_once "ywww/dlog.php"; -include_once "web.php"; +include_once "private/web.php"; function findGenre($browseNode, &$ID, &$gen) { if($browseNode->Name == "Subjects") @@ -61,7 +61,7 @@ $output .= "<BookDetails>"; $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="";
--- 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 @@ <?PHP -include_once "dlog.php"; +include_once "ywww/dlog.php"; session_start(); function uniqueRand($n, $min = 0, $max = null)
--- a/xml/amazonBookSearch.php Sat Jan 05 18:00:10 2019 -0500 +++ b/xml/amazonBookSearch.php Sun Jan 06 07:17:03 2019 -0500 @@ -1,8 +1,8 @@ <?php -include_once "dlog.php"; +include_once "ywww/dlog.php"; -include_once "doAmazonRequest.inc"; +include_once "doAmazonRequest.php"; $Adefault=array( 'language' =>'en', //what language to render the page in
--- 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 @@ -<?php -include_once "dlog.php"; - -include_once "web.php"; -include "aws_signed_request.php"; - -function doAmazonRequest($ext, $parameters, $try, $dbl='x', $wantXML=True) -{ - global $public_key, $private_key; - $requestURI = $_SERVER['REQUEST_URI']; - $requestIP = $_SERVER['REMOTE_ADDR']; - $file_data=$ext; - ksort($parameters); - foreach ($parameters as $i=>$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("/<Error>/",$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"); -} -?>
--- /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 @@ +<?php +include_once "ywww/dlog.php"; + +include_once "private/web.php"; +include "aws_signed_request.php"; + +function doAmazonRequest($ext, $parameters, $try, $dbl='x', $wantXML=True) +{ + global $public_key, $private_key; + $requestURI = $_SERVER['REQUEST_URI']; + $requestIP = $_SERVER['REMOTE_ADDR']; + $file_data=$ext; + ksort($parameters); + foreach ($parameters as $i=>$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("/<Error>/",$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"); +} +?>
--- 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 @@ <?php -include_once "dlog.php"; -include_once "doAmazonRequest.inc"; +include_once "ywww/dlog.php"; +include_once "doAmazonRequest.php"; function getAmazonDet($isbn,$go,$localeIn) {