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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.