1

Not sure whether this is a Craft thing or a Yii thing, but I have this exact same code running on two servers that I've freshly updated Apache, PHP, etc. On the one server it runs fine but on the other the page never loads and I have to do a server reboot to clear it.

Can anyone think of any reason this might happen?

$url = 'https://domain.com/jsonfeed'
try {
    $client = new \Guzzle\Http\Client();
    $request = $client->get($url);

    // BREAK NOW AND ALL IS FINE

    $response = $request->send();

    // BREAK NOW AND PAGE NEVER LOADS SO IT MUST BE
    // $request->send(); THAT IS FAILING

    if (!$response->isSuccessful()) {
        return;
    }

    $items = $response->json();

    reset($items);
    $key = key($items);
    return $items[$key][$id];

} catch(\Exception $e) {
    return;
}
  • Anything in the Apache error logs? I'd guess environmental differences (memory limits, execution times, etc.) Probably worth comparing those on the servers. – Brad Bell Feb 24 '17 at 0:34
  • Thanks Brad. It turned out the providers of the JSON feed had blocked our access but weren't providing an error response. That meant the request had to wait to time out and the website was unresponsive until then. I'm not sure of the solution if it happens again - clearly the site has to wait for a response in case it is just delayed. – Clive Portman Feb 24 '17 at 12:53
  • Yeah... they should be returning a 403 response header or something similar in that case. Oh well... would you mind adding that as an official answer? – Brad Bell Feb 24 '17 at 21:40
1

The problem was the service that was supposed to return the JSON feed was not returning anything. Meaning our server was simply waiting for a response that never arrived and eventually timing out a minute later.

I only discovered this by writing my own script to test for a response from two different servers, discovering the IP address of the server experiencing the problem was being blocked from accessing the JSON feed.

Please, if you're supplying data and decide to block someone's IP, at least tell them you're doing so. An error response would have saved me a lot of work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.