php cron jobs overlapping
Hi I wrote few months back a script in perl for checking overlapping of jobs
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";
开发者_如何学Python sleep $waitseconds;
}#end else
}#end while
if ($lockstatus == 0){
die "no lock was attained\n";
}#end if
}
I wanted to know if we can do similar thing in php ..
How to integrate with your current php code which is running a part of php jobs?
Of course you can. The only specific feature which you use is "flock" and thats available also in php (see flock doc).
The other steps are pretty similar:
- replace "my" with "$"
- init block with a while(1) loop
- die with exit
- and the if cases to php representation
精彩评论