Search code examples
phpoutput-buffering

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?


Solution

  • try

    logit($content);
    //           ^^ Note the missing s