RE: [PHP] Trapping failure of file_get_contents()
| From: | Marshall Burns | Date: | Thu, 22 Oct 2009 17:06:13 +0000 |
| Subject: | RE: [PHP] Trapping failure of file_get_contents() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299227@lists.php.net to get a copy of this message | ||
Robert and others,
I made that change in the code. It still does not trap the failure. I
believe the reason is that the script is timing out while
file_get_contents() is sitting there waiting for input. The problem is that
the function never returns, so there is no return value to check. What I
need is to get file_get_contents() to quit trying before the script timeout
limit is reached, so I can catch the failure and try again. If that cannot
be done, then I need to get the shutdown function to work.
For reference, my original question is at
http://marc.info/?l=php-general&m=125622597723923&w=2
.
Thanks.
-----Original Message-----
From: Robert Cummings [mailto:robert@interjinn.com]
Sent: Thursday, October 22, 2009 08:44
To: Marshall Burns
Cc: php-general@lists.php.net
Subject: Re: [PHP] Trapping failure of file_get_contents()
Marshall Burns wrote:
> I have a script that downloads a sequence of files online. Every hundred
> files or so, it fails with:
Check for the return value being equal to false:
<?php
if( ($sFil = file_get_contents( $sURL )) === false )
{
// FAIL
}
else
{
// SUCCESS
}
?>
Make sure you use the triple '=' comparison operator since you need to
check against the type being boolean also.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP