Jump to content

Recommended Posts

Guys,

 

Just a curious thought, will PHP fail if I was to write to a file (whether append, or overwrite) and there is currently an open read stream from another client? Or will PHP automatically handle this by, for example, waiting for any current streams to close?

 

Thanks,

Brendon

Link to comment
https://forums.phpfreaks.com/topic/257751-question-about-php-file-streams/
Share on other sites

Sometimes yes, sometimes no, and it depends on the system. Assume the worst: you'll have the same file open by multiple processes all doing different things at the same time.

 

You can, however, lock the file and eliminate the guesswork.

Thanks for your input requinix.

 

For example, in the case of images, would it be best to implement caching, whereby a cached image would be returned to the client's browser if the original image was not readable (due to the file lock), or if the original image and the cached image had the same time stamp?

 

I'm guessing this would free up any opportunity to write to the original image? Or do you perhaps know of a better method than this?

 

Thanks,

Brendon

Paranoid? Haha! I was just planning out a script and had a thought come to mind.

But I have worked around it after a few cups of coffee  :P

I have decided just to use caching to prevent any possible read/write collisions from occurring.

It's all good, thanks requinix for your help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.