您好,欢迎访问一九零五行业门户网

一定并发量下,在硬盘上写入文件

= $max_size) { $new_log_file = '/logs/error_' . date('ymdhis') . '.log'; rename($log_file, $new_log_file); } } $fp=fopen($log_file,'a+'); if($fp){ $starttime=microtime(); do{ // 这个循环可以保证进程在尝试1m后,如果未能锁定文件,则放弃写入日志的操作 $canwrite=flock($fp,lock_ex); if(!$canwrite){ usleep(round(rand(0,100)*1000)); } }while((!$canwrite)&&((microtime()-$starttime)<1000)); if($canwrite){ $content = date('y-m-d h:i:s') . ' ' . $log_content . \r\n; fwrite($fp,$content); } fclose($fp); } }
其它类似信息

推荐信息