I have a PHP script running on a cron that can take a long time to process fully (e.g. 10 minutes). What would happen if this script was modified while it's being parsed? or during execution? The reason I ask is I have a number of scripts across servers that I want to place under version control and i'm concerned about what might happen if the script happens to get updated while it is processing. If it is an issue then I could place some kind of lock on the file while it is running.
1 Answer
Nothing should happen to the running script, because by the time it starts running, PHP would have already parsed it and the opcodes are already in memory, so there's no more disk access.
4 Comments
robjmills
I assumed that would be the case once its been parsed and is executing but what if it was changed whilst it was being parsed?
rid
@seengee, unless PHP or the OS is locking it, the resulting executable code will be corrupted.
rid
@seengee, or, more likely, the lexer will try reading the next token and it will encounter garbage instead of what it expects, which would raise a syntax error. Either way, something bad (and unpredictable) will definitely happen if the file is changed before it was fully read.
robjmills
I dd fear as much. the odds of this happening are very low though I would hope and I can probably work around them easily enough. thanks!