php 高并发下写文件
高并发下写文件 [代码片段(18行)]
function write($data) { $return = false; if ($handle = @fopen('error.txt','a+') ) { $i=0; while (!flock($handle,2) && $i++ < 3 ) { usleep(500000); } if ($i < 3 && fwrite($handle,$data . "\\r\\n")) { flock($handle,3); $return = true; } fclose($handle); } return $return; } //该片段来自于http://outofmemory.cn
- 上一篇:php 检查字符串中是否有外链
- 下一篇:php 提取discuz安装进度显示
精彩图集
精彩文章