From 83f84ed7de4f607fbfe72a5221d78acb4351c862 Mon Sep 17 00:00:00 2001 From: Tim Connors Date: Sat, 11 Jul 2015 22:50:10 +1000 Subject: [PATCH 1/4] avoid an endless loop with a recent flickr API update --- Offlickr2.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Offlickr2.php b/Offlickr2.php index 03fc41e..c94fc59 100755 --- a/Offlickr2.php +++ b/Offlickr2.php @@ -396,6 +396,10 @@ private function get_photo_list() { if (count($photos['photo']) == 0) { break; } + if ($page > $photos['pages']) { + printf ("debug: past the end of pages? $page > %s\n", $photos['pages']); + break; + } foreach ($photos['photo'] as $photo) { array_push($this->photo_list, $photo['id']); } From b0e20d390caf3a7ec16100ff7b4ac66b494d3dca Mon Sep 17 00:00:00 2001 From: Tim Connors Date: Sat, 11 Jul 2015 22:52:16 +1000 Subject: [PATCH 2/4] avoid php warnings; don't know what @hugoh's original motivation was for FIXME comment below, but this gets it working for me --- LocalStorage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LocalStorage.php b/LocalStorage.php index 0eb009c..f4e42ee 100644 --- a/LocalStorage.php +++ b/LocalStorage.php @@ -18,6 +18,8 @@ protected function assign_data_value($type, $value) { } function setup_temporary_dir() { + $path="/tmp"; + $prefix="offlickr2."; // FIXME: Not atomic $tempname = tempnam($path,$prefix); if (!$tempname) { From 70a1a255446575c6188ff3e90d737bd2e6155a81 Mon Sep 17 00:00:00 2001 From: Tim Connors Date: Wed, 29 Sep 2021 18:35:11 +1000 Subject: [PATCH 3/4] The flickr API seems to periodically fail with non-sensical return code. Just retry with exponential backoff for 3 tries --- Offlickr2.php | 3 ++- oPhpFlickr.php | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Offlickr2.php b/Offlickr2.php index c94fc59..fff1937 100755 --- a/Offlickr2.php +++ b/Offlickr2.php @@ -397,11 +397,12 @@ private function get_photo_list() { break; } if ($page > $photos['pages']) { - printf ("debug: past the end of pages? $page > %s\n", $photos['pages']); + printf ("DEBUG: past the end of pages? $page > %s\n", $photos['pages']); break; } foreach ($photos['photo'] as $photo) { array_push($this->photo_list, $photo['id']); + printf ("DEBUG: %s %d\n", $photo['id'], $page); } $retrieved = count($this->photo_list); $this->dialog->info(2, "Total so far: " . $retrieved . " photo(s)"); diff --git a/oPhpFlickr.php b/oPhpFlickr.php index afbb74b..7dd5365 100644 --- a/oPhpFlickr.php +++ b/oPhpFlickr.php @@ -27,7 +27,7 @@ function authorize_console() { return $accessToken; } - function request ($command, $args = array()) { + function request ($command, $args = array(), $already_tried=0) { // NOTE: cache not implemented $args = array_merge( @@ -40,15 +40,41 @@ function request ($command, $args = array()) { $request = new OAuthRequest(Verb::POST, $args['url']); foreach ($args as $key => $value) { $request->addBodyParameter($key, $value); + print("*** request[" . $key . "]=" . $value . "\n"); } $this->oauth_service->signRequest($this->token, $request); $response_object = $request->send(); $response = $response_object->getBody(); - $this->parsed_response = json_decode($response, TRUE); +// print("*** response: " . $response . "\n"); + +// if ($args['format'] == 'rest') { + // FIXME: when format = rest, get returned: + +//xml version="1.0" encoding="utf-8" +// +//parsed_response = json_decode($xml, TRUE); +// } else { + $this->parsed_response = json_decode($response, TRUE); +// } if ($this->parsed_response['stat'] == 'fail') { - if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); - else { + if ($this->die_on_error) { + if ($already_tried > 3) { + die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); + } else { + print("warning: (retry {$already_tried}<=3) The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}\n"); + $sleep = 1 * 10**$already_tried; + print("Sleeping {$sleep} seconds\n"); + sleep($sleep); + $already_tried++; + $this->request($command, $args, $already_tried); + } + } else { $this->error_code = $this->parsed_response['code']; $this->error_msg = $this->parsed_response['message']; $this->parsed_response = false; @@ -62,4 +88,4 @@ function request ($command, $args = array()) { } -?> \ No newline at end of file +?> From df9b8702fddb98e1ba5c7b7f6a50001154154fc2 Mon Sep 17 00:00:00 2001 From: Tim Connors Date: Wed, 29 Sep 2021 18:36:48 +1000 Subject: [PATCH 4/4] remove some attempts at parsing the XML before I realised php-xml wasn't installed anymore post php-7.4 upgrade --- oPhpFlickr.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/oPhpFlickr.php b/oPhpFlickr.php index 7dd5365..d2b073e 100644 --- a/oPhpFlickr.php +++ b/oPhpFlickr.php @@ -46,22 +46,7 @@ function request ($command, $args = array(), $already_tried=0) { $response_object = $request->send(); $response = $response_object->getBody(); -// print("*** response: " . $response . "\n"); - -// if ($args['format'] == 'rest') { - // FIXME: when format = rest, get returned: - -//xml version="1.0" encoding="utf-8" -// -//parsed_response = json_decode($xml, TRUE); -// } else { - $this->parsed_response = json_decode($response, TRUE); -// } + $this->parsed_response = json_decode($response, TRUE); if ($this->parsed_response['stat'] == 'fail') { if ($this->die_on_error) { if ($already_tried > 3) {