[PHP] Trapping failure of file_get_contents()

2009-10-22 Thread Marshall Burns
I have a script that downloads a sequence of files online. Every hundred files or so, it fails with: == Warning: file_get_contents(URL) []: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time,

Re: [PHP] Trapping failure of file_get_contents()

2009-10-22 Thread Robert Cummings
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 { //

Re: [PHP] Trapping failure of file_get_contents()

2009-10-22 Thread Jim Lucas
Robert Cummings wrote: 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

RE: [PHP] Trapping failure of file_get_contents()

2009-10-22 Thread Marshall Burns
=125622597723923w=2 . Thanks. -Original Message- From: Robert Cummings [mailto:rob...@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

Re: [PHP] Trapping failure of file_get_contents()

2009-10-22 Thread Robert Cummings
Marshall Burns wrote: 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

Re: [PHP] Trapping failure of file_get_contents()

2009-10-22 Thread Gerardo Benitez
Hi Marshall, the function file_get_contents may have problem with large files. You could try get the file using fread and feof. Here i put a example $contents = ''; while(!feof($stream)){ $contents .= fread($stream, 8192); } Gerardo Benitez. On Thu, Oct 22, 2009 at 12:38 PM,