Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP output buffering to text file

I am having trouble with an update script. It runs for a few hours so I would like it to output live to a text file.

I start the document with

ob_start();

Then within the while loop (as it iterates through the records of the database) I have this

$size=ob_get_length();
if ($size > 0)
{
    $content = ob_get_contents();
    logit($contents);
    ob_clean();
}

And finally the logit function

function logit($data)
{
    file_put_contents('log.txt', $data, FILE_APPEND);
}

However the log file remains empty. What am I doing wrong?

like image 930
Pablo Avatar asked Jul 22 '10 11:07

Pablo


People also ask

What is PHP output buffering?

Output Buffering is a method to tell the PHP engine to hold the output data before sending it to the browser.

What is flush () PHP?

The flush() function requests the server to send its currently buffered output to the browser. The server configuration may not always allow this to happen.

How do I enable output buffering?

It's possible to turn on/off and change buffer size by changing the value of the output_buffering directive. Just find it in php. ini , change it to the setting of your choice, and restart the Web server.


1 Answers

try

logit($content);
//           ^^ Note the missing s
like image 83
jigfox Avatar answered Oct 20 '22 12:10

jigfox