Я запрашиваю API Google, у которого есть абсурдно низкий предел 100/день, и я получаю:
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET ...
.. и сценарий не справляется с этим после этого момента.
Как я могу предотвратить его сбой и, по крайней мере, сохранить все данные, полученные до этого? Я сохраняю данные в массиве:
function searchImages($service, $optParams, $query) {
$results = $service->cse->listCse($query, $optParams);
return $results;
}
$descriptionSearch = searchImages($customsearchService, $customsearchService_optParams, $descriptions[$i]);
foreach ($descriptionSearch->items as $item) {
array_push($list[$item_codes[$i]], strtok($item->link,'?'));
}
function searchImages($service, $optParams, $query) {
try {
$results = $service->cse->listCse($query, $optParams);
}catch (Exception $e) {
// should log this exception... you can use Log4PHP
return NULL;
}
return $results;
}
$descriptionSearch = searchImages($customsearchService,customsearchService_optParams, $descriptions[$i]);
if (!is_null($descriptionSearch)) {
foreach ($descriptionSearch->items as $item) {
array_push($list[$item_codes[$i]], strtok($item->link,'?'));
}
}
try { foreach ... } catch (Exception $e) { echo 'Message: ' .$e->getMessage(); }
?