Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write browser output to log file using PHP?

Tags:

php

io

cron

I have the script is which runned by Cron jobs. So, while it runs, I can't see what output of the task is. (errors and so on.)
So I need to write browser output to log file using PHP. How can I do this ?

like image 666
John Avatar asked Mar 04 '26 13:03

John


1 Answers

You can use output buffers to write browser output to a log file,

Example:

<?php
ob_start();

echo 'Lorem ipsum dolor sit amet consectetur adipiscing elit';
echo 'Cras in dolor fringilla est fermentum porttito';
echo 'bla bla bla...';
echo 'bla bla bla...';

file_put_contents('/path/to/log.txt',ob_get_contents());
ob_end_flush();
?>
like image 163
Zul Avatar answered Mar 06 '26 04:03

Zul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!