This is a discussion on Please help: Prevent Multiple Instances within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, How can I prevent a script from running when a previous instance of the script had already been ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi All,
How can I prevent a script from running when a previous instance of the script had already been triggered and the script is running in the background already? So, even when a script is startet several times (eg. by several website visitors) I want only one script-instance running on the server. Subsequent instances should be exited (or prevented) right away to keep the server load as low as possible. However, when no instance of the script is currently running (eg. after a server shut-down), triggering the script should make it run - but again: only one instance should be running at all times. Further script calls, as said above, should then not be allowed. Any ideas? Thanks a ton if somebady can help me. Jerry |
|
|||
|
Hello,
On 06/07/2004 05:09 AM, Jerry wrote: > How can I prevent a script from running when a previous instance of > the script had already been triggered and the script is running in the > background already? > So, even when a script is startet several times (eg. by several > website visitors) I want only one script-instance running on the > server. Subsequent instances should be exited (or prevented) right > away to keep the server load as low as possible. > > However, when no instance of the script is currently running (eg. > after a server shut-down), triggering the script should make it run - > but again: only one instance should be running at all times. Further > script calls, as said above, should then not be allowed. I use flock() to obtain a lock in a specified file to be associated with the task. The first script to obtain the lock will prevent others to grab it. -- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html |