PHP output buffering to text file

I am having trouble updating the script. It works for several hours, so I would like it to output live to a text file.

I am running a document using

ob_start();

Then in a while loop (since it iterates through the database records), 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?

+3
source share
2 answers

to try

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

$contentsis not the same variable as $content.

0
source

Source: https://habr.com/ru/post/1755957/


All Articles