|
Posted by NC on 09/22/06 16:30
sven.holcombe@gmail.com wrote:
>
> I'm trying to just prevent multiple instances of a script running.
....
> I am on winXP with php5.
Read the documentation:
On some operating systems flock() is implemented at the process
level. When using a multithreaded server API like ISAPI you may
not be able to rely on flock() to protect files against other PHP
scripts running in parallel threads of the same server instance!
http://www.php.net/flock
This is the bad news. The good news is that you don't necessarily
need flock() for this. Here's a possible workaround:
$file = 'foo.txt';
if (file_exists($file)) {
$time = date('Y-m-d H:i:s', trim(file_get_contents($file)));
die('Another instance is running since ' . $time);
}
$fp = fopen($file, 'w');
fwrite($fp, time());
fclose($fp);
// the script goes here...
unlink($file);
Cheers,
NC
Navigation:
[Reply to this message]
|