Forum Moderators: coopster

Message Too Old, No Replies

can a server open only one of the same php file at a moment?

or does it open the same file multiple times if multiple requests?

         

merijnvw

12:50 pm on Jan 30, 2010 (gmt 0)

10+ Year Member



Hi, I have a php file that handles an image, using the GD library. It opens the image, does the actions that a website visitor told it to do, and saves the image. Then another visitor can adjust the saved image. I have to be sure that if the second visitor makes his request while the php is still processing the first visitor's request, the server will wait till the first one is done, then does the second request and the php opens the latest version of the image. Can I be sure about that? Or does the server handle multiple requests at once?

mack

3:04 pm on Jan 30, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Not sure if this can be done directly with php, but you could use a database to store a value (open, closed) when the. User views the file, the page that contains the image reads from db. If closed allow the user access and updats the db to open. If its open advise user to wait.

It's a not very pretty, but would work.

Mack.

Readie

5:46 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I know this isn't my thread or anything, but your response made me wonder something Mack :)

You say have an open/closed value in a database - assuming the user is a good user who always logs out properly I can see how to do it.

But, if the user is like me and is in the habit of just hitting hibernate and disappearing for 5 hours, how would you go about making sure that the database value returns to "open" after an appropriate length of time?

P.S. Sorry for hijacking your thread merijnvw :)

mack

5:51 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Use a timestamp. When ever a user attempts to load the file. If the file is open, and has been for x time close it. The time will depend on what you see as acceptible.

Like I said, it isn't pretty )

Mack.

Readie

5:56 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh, simple enough.

But, say the user does hibernate on the edit image screen, what if the timestamp has expired when he returns, there needs to be something to prevent the user from continuing work on the image while the database value is "open"...

I suppose you could just do an if statement: if timestamp + xx is true, session_destroy();?

mack

6:00 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yea a session would work. Ses the session expire value to the same as the time stamp over write value.

There has to be a neater way! :)

Mack.

rainborick

11:34 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The function you want is called file locking. See flock().

On some shared/mirrored systems, this mechanism is not reliable so you have to replicate the function manually. This is often done by having your software create a specially-named file when the target data file to be modified is in use. When the task is completed, the special file is deleted. You just check file_exists() on the special file before trying to manipulate the target data file. If it's in use, you idle for a bit and check again - usually with a timeout.

merijnvw

10:17 pm on Feb 2, 2010 (gmt 0)

10+ Year Member



Ok that's smart, I'll do that, thanks.
And thanks to the others for thinking with me!
By the way is there a problem here on WebmasterWorld with email notification of replies? I always click on it but don't get the notifications, they're not in my spambox either.

eelixduppy

11:45 pm on Feb 2, 2010 (gmt 0)



>> By the way is there a problem here on WebmasterWorld with email notification of replies?

The system is undergoing changes at the moment. Please be patient.