0

I have set up a cron job which fetches the JSON response from a website, process it and saves it into the database. The Cron Job will be running for more than a week.

I am facing 2 problems:

  1. I expect my cron job to continously run for more than a week if required, but after 2-3 days the cron job stops. The error log does not show any FAILURE. Any idea why the cron job stops without notification.

  2. I get some WARNINGS, while I fetch data using file_get_contents, as failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/... This works in most cases, but some times I get this error, can some one tell me why this occurs.

Regards, Muthukumar

user1262479
  • 497
  • 3
  • 6

1 Answers1

0

you can try this function instead of usual file_get_contents();

function get_contents($url, $ua = 'Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', $referer = 'http://www.google.com/') {
  if (function_exists('curl_exec')) {
    $header[0] = "Accept-Language: en-us,en;q=0.5";
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_USERAGENT, $ua);
    curl_setopt($curl, CURLOPT_REFERER, $referer);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    $content = curl_exec($curl);
    curl_close($curl);
  }
  else { 
    $content = file_get_contents($url);
  }
  return $content;
}