Page 1 of 1

Preventing more than one user from accessing

Posted: Tue Oct 11, 2005 8:21 pm
by fdesensi
I have a section on a site I am developing that I only want one user to access at a time. I have used lock files before with pages that
the user can not access, and they have worked fine. However in this situation, lock files will not work because if the user hits stop then
the page will stop loading, and the lock will stay.

I could fix this, if PHP had a finalize function like java does, but I don't think that it does.

Does anyone have any ideas on how I can prevent more than one user from accessing a file? Or even an alternative to the finalize method?

Posted: Tue Oct 11, 2005 8:42 pm
by feyd
as long as their browser has requested the page, the script will continue processing even if they stopped loading it on their end..

Posted: Tue Oct 11, 2005 9:00 pm
by fdesensi
Hmmm...you are right...

I tried this little test script and what you said
worked.

Code: Select all

if(file_exists("tmp/lock.tmp"))
	{
		die("Another instance is already running...\n\n");
	}
		else
	{
		echo("Access has been given");
		
		$fp = fopen("lock.tmp","w");
		
		echo("Slepping....");
		sleep(10);
		
		unlink("lock.tmp");
	}
However in my real program, this is not the case. Is it possible for the page to crash....
or for the server to terminate execution?

The page in this case was trying to do a very large number of queries so could the page
time out on the server? And if so should I use the set_time_limit(0) function to
solve this issue?

Posted: Tue Oct 11, 2005 9:22 pm
by feyd
The script may quite possibly time out, as the default time a script may stay executing is 30 seconds. As you guessed, set_time_limit() will allow you to alter that time limit.