/**多进程写文件
* @param $filename
* @param $content
* @return bool|int
*/
function write_file($filename, $content)
{
$lock = $filename . '.lck';
$write_length = 0;
while (true) {
if (file_exists($lock)) {
usleep(100);
} else {
touch($lock);
$write_length = file_put_contents($filename, $content, FILE_APPEND);
break;
}
}
if (file_exists($lock)) {
unlink($lock);
}
return $write_length;
}
PHP 多个进程写文件
最新推荐文章于 2023-08-27 13:58:42 发布