Reply to Re: flock won't non-block at all

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация