teamv Posted February 9, 2007 Share Posted February 9, 2007 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 https://forums.phpfreaks.com/topic/37748-setting-a-time-limit-on-file_get_contents-call/ Share on other sites More sharing options...
teamv Posted February 9, 2007 Author Share Posted February 9, 2007 By the way this is a time limit on that small function call, not the entire script. I had found a set_time_limit but that works only for the whole script. Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/37748-setting-a-time-limit-on-file_get_contents-call/#findComment-180639 Share on other sites More sharing options...
teamv Posted February 9, 2007 Author Share Posted February 9, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/37748-setting-a-time-limit-on-file_get_contents-call/#findComment-180794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.