Perl集群不能在CGI中工作
(在运行以下脚本之前,将 /home/porton/t/MOVE 替换为您有权创建或删除的文件的路径。)
当我从命令行启动此脚本并在 10 秒内从命令启动相同的脚本再次行,它打印出我所期望的:
Flock: 1
和
Flock: 0
相应的。
但是当我作为 CGI 运行它两次(请求时间间隔小于 10 秒)时,即 http://test.localhost/cgi-bin/test2.pl 它会打印
Flock: 1
两个 CGI 请求。
错误是什么?为什么从 CGI 运行时它会以不同的、意想不到的方式表现?
#!/usr/bin/perl
use strict;
use warnings;
use Fcntl qw(:flock);
print "Content-Type: text/plain\n\n";
open(my $lock_fh, '>', "/home/porton/t/MOVE");
print "Flock: " . flock($lock_fh, LOCK_EX|LOCK_NB) . "\n";
sleep 10;
(Before running the below script replace /home/porton/t/MOVE with a path to a file you have the right to create or erase.)
When I start this script from the command line and during 10 secs start the same script from command line again, it prints what I expect:
Flock: 1
and
Flock: 0
correspondingly.
But when I run it twice (with interval between the time of the requests less than 10 secs) as CGI that is as http://test.localhost/cgi-bin/test2.pl it prints
Flock: 1
for both two CGI requests.
What is the error? Why it behaves in a different unexpected way when run from CGI?
#!/usr/bin/perl
use strict;
use warnings;
use Fcntl qw(:flock);
print "Content-Type: text/plain\n\n";
open(my $lock_fh, '>', "/home/porton/t/MOVE");
print "Flock: " . flock($lock_fh, LOCK_EX|LOCK_NB) . "\n";
sleep 10;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定这两个请求是并行运行的吗?它们可以按顺序处理,即可以在第一个请求完成之后并且在释放锁之后处理第二个请求。
Are you sure the two requests are running in parallel? They might be handled sequentially, i.e. the second request could be processed after the first one is completed, and after the lock has been released.