Jump to content

Dealing with file_get_contents errors?


python72

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/221184-dealing-with-file_get_contents-errors/
Share on other sites

"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.

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/');
}

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.