Reply to Re: Ensure only one instance of a script is running

Your name:

Reply:


Posted by Raj Shekhar on 03/16/05 20:10

"Jay Blanchard" <jay.blanchard@niicommunications.com> writes:

> [snip]
> 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?
> [/snip]
>
> Don't run another instance. ba-dump ching!
>
> Ok, here is a quick and dirty way to do it, have the script check for
> the existence of a file containing a date and timestamp, if one does not
> exist the script creates one. If it does exist, the script exits. Once
> the script is nearing completion have it destroy the file (unlink).


Unluckily, this will not prevent a race condition. The only file
operations that are guaranteed to be atomic are mkdir() and
symlink(). Try to create the directory and see if it fails. Also
remember to rmdir() the lock directory before exiting

--
Raj Shekhar Y! : Operations Engineer
MySQL DBA, programmer and slacker Y!IM : lunatech3007
home : http://rajshekhar.net blog : http://rajshekhar.net/blog/

[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

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