[-] Fix race condition leading to file corruption and PHP crashes

Handles concurrency properly, avoiding race condition that leads to PHP parsing errors or PHP crashes.