0

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 1

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
@seengee, unless PHP or the OS is locking it, the resulting executable code will be corrupted.
@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.
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.