Jump to content

Setting a time limit on file_get_contents() call?


teamv

Recommended Posts

Hi all,

 

Is there any way I can set a time limit on a file_get_contents call? Basically I'm runing a query on geo-coding API and extracting the co-ordinates from the resulting string. Heres the code:

 

$geoquery = "thequery";

$georesult = file_get_contents("http://www.theapi.com/?$geoquery");

 

preg_match_all('/-?(?:\d+)?\.\d+/', $georesult, $coordinates);

 

$longitude = $coordinates[0][0];

$latitude = $coordinates[0][1];

 

When the postcode is valid it returns the string from which I can extract the co-ordinates. However when it is invalid it does not, it simply keeps trying and trying and eventually the connection to the api is blocked with 'connection refused in xxxx'.

 

I was wondering if there was any way that I could set a time limit on the file_get_contents request? For example to say that if its still running 7 seconds later to stop trying and and move onto the next loop. Any ideas?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.