Use thinkphp5 0 framework. It is found that sometimes the logs are lost at a certain time, but the database updates are correct. The encapsulated log function can also lose the log. Can you write the log by setting the file lock?, such asflock($fp, LOCK_EX)
, elder brothers, is there a good way to solve the problem of not losing your days…..
function log($folder = 'debug', $msg)
{
$path = LOG_PATH . $folder;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$filename = $path . '/' . date('Ymd') . '.txt';
$content = date("Y-m-d H:i:s") . "\r\n" . print_r($msg, 1) . "\r\n \r\n \r\n ";
if (!is_file($filename)) {
touch($filename);
chmod($filename, 0777);
}
file_put_contents($filename, $content, FILE_APPEND);
}
This work adoptsCC agreement, reprint must indicate the author and the link to this article