python72 Posted December 10, 2010 Share Posted December 10, 2010 I am using file_get_contents to get file off the internet for further processing but somtetimes there is error fetching that file off the web in which case it would be nice to try to reload it again but I am not sure what would be best way to do it? How can I jump back on error? I guess there would have to be some jump to label condition, but how do I implement this? Quote Link to comment https://forums.phpfreaks.com/topic/221184-dealing-with-file_get_contents-errors/ Share on other sites More sharing options...
requinix Posted December 10, 2010 Share Posted December 10, 2010 "jump to label"? No. Just no. If you're thinking about timeouts and 500 errors and such, cURL is easier to use than a similar built-in solution using stream contexts. Otherwise a simple for or while loop is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/221184-dealing-with-file_get_contents-errors/#findComment-1145225 Share on other sites More sharing options...
python72 Posted December 10, 2010 Author Share Posted December 10, 2010 If I have the following: $Page = file_get_contents('http://www.google.com/'); The $Page variable would be null till the page loads completely? Now using the while would I have the following? $Page=Null; while($Page == Null){ $Page = file_get_contents('http://www.google.com/'); } Quote Link to comment https://forums.phpfreaks.com/topic/221184-dealing-with-file_get_contents-errors/#findComment-1145233 Share on other sites More sharing options...
trq Posted December 10, 2010 Share Posted December 10, 2010 file_get_contents returns false on failure, not null. Quote Link to comment https://forums.phpfreaks.com/topic/221184-dealing-with-file_get_contents-errors/#findComment-1145234 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.