Jump to content

Question about PHP file streams.


brendon

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.