PHP中关于flock的有关问题
PHP中关于flock的问题
关于flock的问题,我在博客上整体了下,http://www.shionco.com/archives/php_flock.html
例程代码:
$fd = fopen('./a.html', 'wb');
if ($fd) {
if (@flock($fd, LOCK_EX|LOCK_NB)) {
echo '未锁,打开文件并加锁';
sleep(10);
} else {
print '已锁,关闭文件';
}
fclose($fd);
} else {
echo '打开文件失败';
}
我在FF下,建立2个页面,打开第一个页面运行,独占锁定成功,进入延时状态,马上打开第2个页面运行,结果第2页发生阻塞,等到第1页运行结束,第2页也独占锁定成功,进入延时状态,执行完毕,明明使用了LOCK_NB,但并未发生独占锁定失败。无论是新建标签页或新窗口都会发生阻塞!
然而在IE下(我使用的是IE9,别的未测试),同样的流程,第2页直接独占锁定失败,输出"已锁,关闭文件";
如果是这样,FF的客户端大量浏览发生内容更新的缓存文件,岂不是都会阻塞?
------解决方案--------------------
你可以这样验证,再创建一个文件,包含上述代码
试着用标签式浏览器分别打开这两个文件,,,,看看是否达到你的需求。。如果是,就是上述原因

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
