ThinkPHP高并发场景改日志文件名报错的解决办法

PHP Fatal error:  Uncaught think\exception\ErrorException: rename(/data/www/houduan_internet_hospital_data/runtime/log/202309/27.log,/data/www/houduan_internet_hospital_data/runtime/log/202309/1695756888-27.log): No such file or directory in /data/www/houduan_internet_hospital_data/thinkphp/library/think/log/driver/File.php:53Stack trace:#0 [internal function]: think\Error::appError(2, 'rename(/data/ww...', '/data/www/houdu...', 53, Array)#1 /data/www/houduan_internet_hospital_data/thinkphp/library/think/log/driver/File.php(53): rename('/data/www/houdu...', '/data/www/houdu...')#2 /data/www/houduan_internet_hospital_data/thinkphp/library/think/Log.php(157): think\log\driver\File->save(Array)#3 /data/www/houduan_internet_hospital_data/thinkphp/library/think/Error.php(84): think\Log::save()#4 [internal function]: think\Error::appShutdown()#5 {main}  thrown in /data/www/houduan_internet_hospital_data/thinkphp/library/think/log/driver/File.php on line 53

在php_error.log日志文件中有大量信息堆积

追溯代码到文件  \thinkphp\library\think\log\driver\File.php

代码如下:

  public function save(array $log = [], $depr = true)
    {
        $now         = date($this->config['time_format']);
        $destination = $this->config['path'] . date('Ym') . DS . date('d') . '.log';

        $path = dirname($destination);
        !is_dir($path) && mkdir($path, 0755, true);

        //检测日志文件大小,超过配置大小则备份日志文件重新生成
        if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) {
            rename($destination, dirname($destination) . DS . $_SERVER['REQUEST_TIME'] . '-' . basename($destination));
        }
}

在rename前面添加@符号,如下:

@rename($destination, dirname($destination) . DS . $_SERVER['REQUEST_TIME'] . '-' . basename($destination));
     

即可解决报错问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值