1. 程式人生 > 遊戲 >SE官方釋出《漫威復仇者》黑豹免費DLC最新宣傳片

SE官方釋出《漫威復仇者》黑豹免費DLC最新宣傳片

場景:在伺服器上添加了一個定時刪除cache快取檔案的任務,由於在執行之後會在runtime中生成一個檔案,如果正好是月初一號就會建立這個月份的資料夾,由於這個自動任務是root使用者執行,執行專案寫日誌是www使用者,所以當專案執行再寫入日誌時會沒有許可權。

出現報錯

PHP Fatal error: Uncaught exception ‘think\exception\ErrorException’ with message ‘error_log(D:\web\xinluchuntian.com\minishop\runtime\log\201702\11.log): failed to open stream: Permission denied’ in D:\web\xinluchuntian.com\minishop\core\library\think\log\driver\File.php:98
Stack trace:
#0 [internal function]: think\Error::appError(2, ‘error_log(D:\we…’, ‘D:\web\xinluchu…’, 98, Array)
#1 D:\web\xinluchuntian.com\minishop\core\library\think\log\driver\File.php(98): error_log(’[ 2017-02-11T17…’, 3, ‘D:\web\xinluchu…’)
#2 D:\web\xinluchuntian.com\minishop\core\library\think\Log.php(157): think\log\driver\File->save(Array)
#3 D:\web\xinluchuntian.com\minishop\core\library\think\Error.php(84): think\Log::save()
#4 [internal function]: think\Error::appShutdown()
#5 {main}
thrown in D:\web\xinluchuntian.com\minishop\core\library\think\log\driver\File.php on line 98

解決辦法,需要修改兩個位置,首先按找到thinkphp/library/log/driver/file.php

當前tp5版本:5.0.15
1. 找到56行(不同tp版本可能會不一樣,save方法中)
!is_dir($path) && mkdir($path, 0755, true);
1
修改為

!is_dir($path) && mkdir($path, 0755, true) && chmod($path,0777);
1
2.找到128行(不同tp版本可能會不一樣,write方法中)
return error_log($message, 3, $destination);
1
修改為

if (!is_file($destination)) {
$first = true;
}

$ret = error_log($message, 3, $destination);
try {
if (isset($first) && is_file($destination)) {
chmod($destination, 0777);
unset($first);
}
} catch (\Exception $e) {

}
return $ret;