PHP. Save information into text/log file. Bacis examples.

Simple example for save information to file on server by PHP

$content = '[' . date('Y-m-d H:i:s') . ']: test info log' . PHP_EOL . '------------' . PHP_EOL;
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/save_test.log", "a+");
fwrite($fp, $content);
fclose($fp);

Error log using example(logs $content [array|string|object] to the log file):

$obj = new StdClass();
$content = [$obj, [3, 51, '4k']];
error_log('[' . date('Y-m-d H:i:s') . ']:' . PHP_EOL . print_r($content, TRUE) . PHP_EOL, 3, $_SERVER['DOCUMENT_ROOT'] . "/save_test.log");

Also you can use file_put_contents method:
Continue reading PHP. Save information into text/log file. Bacis examples.