2016-06-14 60 views

回答

1

簡單的方法:

file_put_contents(ini_get('error_log'), ''); 
error_log("Houston, we have a problem.", 0); 

這隻會工作,如果正在執行該用戶有這樣做的權限(寫訪問此文件)。

否則,您可以set a other location for your runtime - 在您有權訪問此日誌的位置。就像這樣:

ini_set('error_log', __DIR__ . DIRECTORY_SEPARATOR . 'error.log'); 
#     ^full path with leading slash 

如果你要備份的文件,而不是你可以與oneliner做到這一點:

file_put_contents(pathinfo(ini_get('error_log'), PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'php_error_backup_'.time().'.log', file_get_contents(ini_get('error_log')));

Oneliner解釋/展開:

$save_location = pathinfo(ini_get('error_log'), PATHINFO_DIRNAME); 
$backup_filename = $save_location . DIRECTORY_SEPARATOR . 'php_error_backup_'.time().'.log'; 
$backup_content = file_get_contents(ini_get('error_log')); 
file_put_contents($backup_filename, $backup_content);