Home >php教程 >PHP源码 >一道php面试题不懂,望各位网友指点指点

一道php面试题不懂,望各位网友指点指点

PHP中文网
PHP中文网Original
2016-05-25 16:59:061572browse

一道php面试题不懂,望各位网友指点指点

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;
}

我测试了下这段代码可以实现,多进程同时写入写入文件
但是我不明白为什么这里的unlink($lock)没有把这个对应的文件删除呢?
而如果把unlink($lock)单独拿出来是可以删除$lock的,所以应该不是没权限的原因
哪位高手知道一下小弟,感激不尽

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn