Hi all,
I have a script which I need to run which takes anywhere from 10-20 minutes to proccess all of the information. (Lots of mathematical calculations) Clearly, I do not want to have the user to sit and stare at the screen, so I'd rather save the output to a file and than give the user a link to the cached output.

My problem is that I can't get the script to save its entire output into an html file, it always gets cut off. Ie..

$url = "http://xxx.xxx.com/xxx/report.php?sid=xxx&month=xxx&year=xxx";


$HTML_output = "";

$read = fopen ( $url , "r" ); 

	// read the HTML output
        while ($line = fgets ( $read , 256 ))
                   {
	    $HTML_output.= $line ."\n";
		}
	fclose ( $read );


	//write stuff

	$fp = fopen($save_path.'/'.$dest, 'a'); #open for writing
	fputs($fp, $HTML_output;); #write all of $data to our opened file
	fclose($fp); #close the file


The problem is, sometime around 800KB of script output the file gets saved, when I know there is more output coming. Any ideas why? Better yet, is there a better way to direct the output of a php script directly to a file?

Thanks for all ideas and suggestions.

    php scripts are by default set to timeout after 20 seconds (i think), you can however change this setting in your php.ini.

    you might also want to look at output buffering and [man]ob_get_contents[/man] for a better method to output to a file.

      thorpe wrote:

      php scripts are by default set to timeout after 20 seconds (i think), you can however change this setting in your php.ini.

      you might also want to look at output buffering and [man]ob_get_contents[/man] for a better method to output to a file.

      that is correct, if you go into your php.ini file and change the following entry:-

      max_execution_time = 30

      this is in seconds, i dont know if it is the same or not in PHP 5

      Shaun

        I used your suggestions and then a bit. In case anyone else is having the same problem, increaseing the max_execution time & using ob_flush() every loop itteration to send the output prevents the script from hanging and let's it finish.

          Write a Reply...