PHP写日志的实现方法

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP写日志的实现方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
function logError($content) 

  $logfile = '/logs/debuglog'.date('Ymd').'.txt'; 
  if(!file_exists(dirname($logfile))) 
  { 
    @File_Util::mkdirr(dirname($logfile)); 
  } 
  error_log(date("[Y-m-d H:i:s]")." -[".$_SERVER['REQUEST_URI']."] :".$content."\n", 3,$logfile); 
}

 
这里注意需要给记日志的目录权限:
复制代码 代码如下:
chown -R  www:www csevent/

如果你的apache里配的不是www你要改为对应的
可以用ll命令查看你的权限

希望本文所述对大家的PHP程序设计有所帮助。

相关文章

中英文字符串翻转函数

复制代码 代码如下:<?php //页面编码设为utf8 header('Content-type: text/html; charset=utf-8'); $luokuan =...

启用Csrf后POST数据时出现的400错误

最近一直出现这样的错误,一直在查找原因,偶然看到一篇解决的文章,分享给大家看看。 第一种解决办法是关闭Csrf public function init(){ $this->...

PHP number_format() 函数定义和用法

number_format() 函数通过千位分组来格式化数字。 语法 number_format(number,decimals,decimalpoint,separator)...

php计算到指定日期还有多少天的方法

本文实例讲述了php计算到指定日期还有多少天的方法。分享给大家供大家参考。具体如下: function countdays($d) { $olddate = substr($d,...

/etc/php-fpm.d/www.conf 配置注意事项

1、php-fpm 配置文件里 rlimit_files的值 要与系统的打开连接数一致 1)查看系统文件打开连接数 [root@iZ94eveq0q4Z ~]# ulimit -n 65...