您好我几个月前在perl写了一个用于检查作业重叠的脚本
use Fcntl ':flock';
INIT {
my $waitcount=12; # possible attemtps to run script
my $waitseconds=300; # wait for $waitseconds each attempt
my $lockstatus=0;#no lock was attained
while ($waitcount > 0){
if (open LH, $0){
while ($waitcount > 0){
if (flock LH, LOCK_EX|LOCK_NB){
$waitcount=0;#signal end of waiting
$lockstatus=1;#lock was attained
}
else{
--$waitcount;#decrement waitcount
print "waiting to be able to lock $0\n";
sleep $waitseconds;
}#end else
}#end while
}#end if
else{
--$waitcount;#decrement waitcount
print "waiting to be able to open $0\n";
sleep $waitseconds;
}#end else
}#end while
if ($lockstatus == 0){
die "no lock was attained\n";
}#end if
}
我想知道我们是否可以在php中做类似的事情。
如何与运行部分php作业的当前php代码集成?
答案 0 :(得分:0)
当然可以。您使用的唯一特定功能是“flock”,也可以在php中使用(参见flock doc)。
其他步骤非常相似: