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, or established connection failed because connected host has
failed to respond. in <script>.php on line <number>

Fatal error: Maximum execution time of 30 seconds exceeded in <script>.php
on line <number>



I have tried to trap this so that I could loop back and let the script try
the access again. Failing that, I've also tried to get a shutdown function
to give me a restart link. The code for this is:



$bWorking = true;



            $bDone = false;

            while(! $bDone)

               {$sFil = file_get_contents($sURL);


                           {$sFileSize = file_put_contents('image/' . $sID .
'.jpg', $sFil);

                                    $bDone = true;}


                           {echo('<br>DL error on ' . $sURL);

                                    $sFileSize = 'DL error';


                        echo(', got ' . $sFileSize);




$bWorking = false;



function ReadFileTimeout()

            // Provide a link to restart processing after a timeout in

   {global $bWorking, $sParameters;


                        echo('<p><a HRef="<script>.php?parameters=' .
$sParameters . '" target="_blank">Restart</a>');




None of that is working. I guess the loop doesn't work because the warning
is emitted after the script has already been aborted by the timeout. But in
that case, the shutdown function should kick in, but the link is not being


So two questions: 

            (a) Is there a way to get file_get_contents() to stop trying
before the script time limit is reached, so that my loop could work?

            (b) Why is the shutdown function not working?


Thanks for your help.








Reply via email to