我正在嘗試創建一個日誌文件,但該文件使用相同的字符串寫入兩次。我該怎麼做才能避免這種行爲?嘗試寫入文件時出現重複輸入
$file = 'newfile.txt';
$current = file_get_contents($file);
$current = time()."\n";
file_put_contents($file, $current, FILE_APPEND | LOCK_EX);
/* output
1471958308
1471958308
1471958312
1471958312
1471958734
1471958734
*/
你是否從網上運行這個文件?嘗試從控制檯運行它。 –
你的代碼如何被觸發? –
嘗試使用error_log()函數 –