brendon Posted February 25, 2012 Share Posted February 25, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257751-question-about-php-file-streams/ Share on other sites More sharing options...
requinix Posted February 25, 2012 Share Posted February 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257751-question-about-php-file-streams/#findComment-1321064 Share on other sites More sharing options...
brendon Posted February 25, 2012 Author Share Posted February 25, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257751-question-about-php-file-streams/#findComment-1321065 Share on other sites More sharing options...
requinix Posted February 25, 2012 Share Posted February 25, 2012 Can you describe your situation more? It almost sounds like you're being a bit paranoid. Quote Link to comment https://forums.phpfreaks.com/topic/257751-question-about-php-file-streams/#findComment-1321096 Share on other sites More sharing options...
brendon Posted February 28, 2012 Author Share Posted February 28, 2012 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/257751-question-about-php-file-streams/#findComment-1321867 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.