I'm trying to extract a small amount of data from another website but I am finding that it is timing out. I've put some coding clauses in place to try and force my code to obtain data from a similar data if trying to obtain it from the first takes too long.
$ctx = stream_context_create(array('http' => array('timeout' => 2)));
$geo = json_decode(file_get_contents($url, 0, $ctx), true);
In principle this should time out after 2 seconds and then I'll know its duff and go for the second URL. But it doesn't work, and tries to get it for 15 seconds. I've tried recplacing the $ctx with
ini_set('default_socket_timeout', 2);
But this doesn't work either. Can anyone please suggest something else I could try?