Process B is reverting the changes of Process A because the expiry.php isn't reloaded before it's written.

Suggestion:
a) Reload the expiry.php before it's written
b) Only update the changed keys and only update the keys if they are older than the current one.

The first solution will be only reloading the expiry.php before it's written.

The longtime solution should be: Doing a "expiry.php" queue like the async. So, every update request should be written in a db table and a daemon is updating the expiry.php every x seconds - if there are changes.