This is a rather simple situation. I've got a template engine that over the course of one page request will include() one/several file(s). Simple enough.
This particular site does not have scheduled updates as much as I'm always tinkering with the code, often to fix a one/two line bug that a user takes note of. Right now, I'll just crack open the ftp client and upload that sucker. In the past, this would work fine, but now, the second it might take to upload a file is enough time to register a few include() requests for that file. php reads the file (which is in mid-upload), doesn't get all of it, then throws a parsing error when it doesn't find the rest of the file.
So, I'd like to write a simple 'update' script that locks the file, upload/overwrites it, then unlocks it. flock() seems to be what I'm looking for, but I'm not entirely clear on its effects. Since this is being done to prevent problems in a high traffic situation, it's not something I can easily replicate on a dev server. So, I'd love to know the following:
a)when a file is flock()ed, do any other requests to create a file pointer (for reading) on that file get rejected, or just get blocked until the lock is released?
b)The php docs state
PHP supports a portable way of locking complete files in an advisory way (which means all accessing programs have to use the same way of locking or it will not work).
Now...does this mean that my templating program needs to have code that checks for a lock of sorts, or can it access the files in the same way it always has (since it's only acting as a reader, and not a writer)
From looking over the code samples in the docs, the writer process might need to loop before it can acquire a lock, but since the readers don't need exclusive access, they won't need a lock, and therefore won't need to ever do a sleep loop, right?
As always, thanks in advance!