You are here: Re: Ensure only one instance of a script is running « PHP « IT news, forums, messages
Re: Ensure only one instance of a script is running

Posted by Zini10 on 03/20/05 13:07

a more reliable solution:
Write a lock file and update timestamp each minute or so ,(at varous places
around the script)
then in order to check if the script is already runninh, check the
timestamp.

"Jeremiah Fisher" <thisisroot@gmail.com> wrote in message
news:20050317141000.93781.qmail@lists.php.net...
> Test for a lock file when the script starts, and remove it when the script
> ends. This isn't 100% reliable, but it's the typical solution to this
> problem. If the script fails, the lock file may not be removed (ever have
> a Mozilla browser crash and tell you the default profile is locked?), so
> be careful with your error handling!
>
> <?php
>
> // test for lock file
> if ( !$f = fopen( 'lock', 'r')) {
> // touch the lock file
> $f = fopen( 'lock', 'w');
> fwrite( $f, 'lock');
> fclose( $f);
>
> } else {
> // lock file exists; another instance must be running (we hope)
> echo 'Error: An instance of this script is already running!';
> exit( 1);
>
> }
>
>
> /* script stuff */
>
>
> // remove the lock file for the next instance
> unlink( 'lock');
>
>
> ?>
>
> Shaun wrote:
>> Hi,
>>
>> I have a script that inserts data from files uploaded to our server. I
>> need to make sure that only one instance of this script runs at anyone
>> time, can anyone tell me how I can do this?
>>
>> Many thanks

 

Navigation:

[Reply to this 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

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