Mercurial > hg > ywww
changeset 9:232deb0b066a
tidy up debugging, only show parms on non-throttled error
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 18 Feb 2017 11:38:36 +0000 |
parents | 226f00d9f6f5 |
children | 5aa24c984a3b |
files | php/read/getBookDetails.php xml/getAmazonInfo.php |
diffstat | 2 files changed, 121 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/php/read/getBookDetails.php Fri Feb 17 15:22:53 2017 +0000 +++ b/php/read/getBookDetails.php Sat Feb 18 11:38:36 2017 +0000 @@ -189,9 +189,6 @@ } - file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ". - print_r($parameters,TRUE)."\n",FILE_APPEND); - $ext=$Aserver[$locale]['ext']; $file_data=$ext; ksort($parameters); @@ -213,131 +210,138 @@ //echo $out; - if (preg_match("<Error>",$out)) { - $xml = new SimpleXMLElement($out); - $resName=$xml->getName(); - $code=$xml->Error->Code; - file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, ". - $xml->Error->Code."\n",FILE_APPEND); - } - else { - $xml = new SimpleXMLElement($out); - //use this xml to pull out the necessary information and save it - set_error_handler(function () { - global $out,$isbn; - file_put_contents('/var/ywww/debug/phpDebug', - "Caught one bd: ".$isbn, - FILE_APPEND); - file_put_contents('/var/ywww/debug/phpDebug', - print_r($out, TRUE)."\n", - FILE_APPEND); - } ); + if (preg_match("<Error>",$out)) { + $xml = new SimpleXMLElement($out); + $resName=$xml->getName(); + $code=$xml->Error->Code; + file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code\n",FILE_APPEND); + if ($code=='RequestThrottled') { + usleep(200000); // Try to reduce throttling until we get a + // principled solution in place + } + else { + file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ". + print_r($parameters,TRUE)."\n",FILE_APPEND); + } + } + else { + $xml = new SimpleXMLElement($out); + //use this xml to pull out the necessary information and save it + set_error_handler(function () { + global $out,$isbn; + file_put_contents('/var/ywww/debug/phpDebug', + "Caught one bd: ".$isbn, + FILE_APPEND); + file_put_contents('/var/ywww/debug/phpDebug', + print_r($out, TRUE)."\n", + FILE_APPEND); + } ); - $title=""; - $author=""; - $binding=""; - $dewey=""; - $imageURL=""; - $salesRank=""; - $pubDate=""; - $publisher=""; + $title=""; + $author=""; + $binding=""; + $dewey=""; + $imageURL=""; + $salesRank=""; + $pubDate=""; + $publisher=""; - $title = $xml->Items->Item->ItemAttributes->Title; - $author = $xml->Items->Item->ItemAttributes->Author; - $binding = $xml->Items->Item->ItemAttributes->Binding; - $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; - if($dewey == "") - $dewey = "null"; - $imageURL = $xml->Items->Item->MediumImage->URL; - $salesRank = $xml->Items->Item->SalesRank; - $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; - $publisher = $xml->Items->Item->ItemAttributes->Publisher; - restore_error_handler(); - /*echo $title; - echo $author; - echo $binding; - echo $dewey; - echo $imageURL; - echo $salesRank; - echo $pubDate; - echo $publisher;*/ + $title = $xml->Items->Item->ItemAttributes->Title; + $author = $xml->Items->Item->ItemAttributes->Author; + $binding = $xml->Items->Item->ItemAttributes->Binding; + $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; + if($dewey == "") + $dewey = "null"; + $imageURL = $xml->Items->Item->MediumImage->URL; + $salesRank = $xml->Items->Item->SalesRank; + $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; + $publisher = $xml->Items->Item->ItemAttributes->Publisher; + restore_error_handler(); + /*echo $title; + echo $author; + echo $binding; + echo $dewey; + echo $imageURL; + echo $salesRank; + echo $pubDate; + echo $publisher;*/ - $genreID = ""; - $genre = ""; - $genArr = array(); - $g1 = "null"; - $g2 = "null"; - $g3 = "null"; - if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ - for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ - //sexy recursive function - findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); + $genreID = ""; + $genre = ""; + $genArr = array(); + $g1 = "null"; + $g2 = "null"; + $g3 = "null"; + if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ + for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ + //sexy recursive function + findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); - if($genre != "") - $genArr[strval($genreID)] = strval($genre); - //$genArr[$i] = array(strval($genreID) => strval($genre)); + if($genre != "") + $genArr[strval($genreID)] = strval($genre); + //$genArr[$i] = array(strval($genreID) => strval($genre)); - //echo $genre; - //echo $genreID; + //echo $genre; + //echo $genreID; - $genre = ""; - $genreID = ""; - } + $genre = ""; + $genreID = ""; + } - $g1 = "null"; - $g2 = "null"; - $g3 = "null"; - $loop = 1; + $g1 = "null"; + $g2 = "null"; + $g3 = "null"; + $loop = 1; - foreach ($genArr as $key => $value) { - //echo "$key => $value"; - $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table - //echo $queryG; - $resG = mysqli_query($link, $queryG); + foreach ($genArr as $key => $value) { + //echo "$key => $value"; + $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table + //echo $queryG; + $resG = mysqli_query($link, $queryG); - switch ($loop) { - case 1: - $g1 = $key; - break; - case 2: - $g2 = $key; - break; - case 3: - $g3 = $key; - break; - } + switch ($loop) { + case 1: + $g1 = $key; + break; + case 2: + $g2 = $key; + break; + case 3: + $g3 = $key; + break; + } - $loop++; - } - } + $loop++; + } + } - if($salesRank == "") - $salesRank = "null"; + if($salesRank == "") + $salesRank = "null"; - mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop - include "../../../private/db.php"; + mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop + include "../../../private/db.php"; - $title = strtr($title, '"', "'"); - $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; - //echo $queryInsert; + $title = strtr($title, '"', "'"); + $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; + //echo $queryInsert; - $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); - mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop + $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); + mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop - $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; - $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; - $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; - $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; - $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; - $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; - $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; - $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; - $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; - $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; - $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; - $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; - $output .= "<ProductGroup>Book</ProductGroup>"; + $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; + $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; + $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; + $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; + $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; + $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; + $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; + $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; + $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; + $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; + $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; + $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; + $output .= "<ProductGroup>Book</ProductGroup>"; } }
--- a/xml/getAmazonInfo.php Fri Feb 17 15:22:53 2017 +0000 +++ b/xml/getAmazonInfo.php Sat Feb 18 11:38:36 2017 +0000 @@ -94,8 +94,6 @@ $url=aws_signed_request($ext,$parameters,$public_key,$private_key); //echo $url; - file_put_contents('/var/ywww/debug/phpDebug',"parms: $go". - print_r($parameters,TRUE)."\n",FILE_APPEND); $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); @@ -117,12 +115,15 @@ $xml = new SimpleXMLElement($output); $resName=$xml->getName(); $code=$xml->Error->Code; - file_put_contents('/var/ywww/debug/phpDebug',"Losing: $resName, ". - $code."\n",FILE_APPEND); + file_put_contents('/var/ywww/debug/phpDebug',"Losing: $resName, $code\n",FILE_APPEND); if ($code=='RequestThrottled') { usleep(200000); // Try to reduce throttling until we get a // principled solution in place } + else { + file_put_contents('/var/ywww/debug/phpDebug',"parms: $go\n". + print_r($parameters,TRUE)."\n",FILE_APPEND); + } } else { $xml = new SimpleXMLElement($output);