Preventing more than one user from accessing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
fdesensi
Forum Newbie
Posts: 11
Joined: Tue Oct 11, 2005 6:17 pm
Location: Pittsburgh

Preventing more than one user from accessing

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
fdesensi
Forum Newbie
Posts: 11
Joined: Tue Oct 11, 2005 6:17 pm
Location: Pittsburgh

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply