Forum Moderators: coopster

Message Too Old, No Replies

Avoid Concurrent Process?

         

humandesigner

9:21 am on Apr 9, 2005 (gmt 0)

10+ Year Member



Hello,

Does anyone know how I could possibly prevent a script from being run by more than one user at the same time on PHP4?

I have a script that has to do some maintenance on a web site.
It is called on every page because cronjobs aren't permitted on the server.

Of course, the script was designed in such a way that the maintenance is skipped when it's already done.

The problem is that when I refresh a page from two different computers at the same time, it disrupts the maintenance process. It seems that the script doesn't have enough time to find out whether or not the maintenance has been already completed.

I could call the script only from the home page but there is a possibility that two users hit that page at the same time.

Any solution?

ironik

10:06 pm on Apr 10, 2005 (gmt 0)

10+ Year Member



The only way I could think of to prevent it would be to employ some sort of locking. In an article system I'm writing, when someone edits an article an entry is made in the database (a lock with expiry time) which is the first thing the article looks for when opening. You could use a similar concept (perhaps create a lock file that is deleted when maintenance is complete). It won't completely solve your problem, but it might help.