A Perl script (which I do not control) appends lines to the end of a text file periodically.
I need my PHP script (which will run as a cron job) to read the lines from that file, process them, and then remove them from the file. But, it seems like the only way to remove a line from a file with PHP is to read the file into a variable, remove the one line, truncate the file, and then rewrite the file.
But what happens if:
- PHP reads the file
- The Perl Script appends a new line.
- The PHP script writes the modified buffer back over the file.
In that case the new line would be lost because it would be overwritten when the PHP script finishes and updates the file.
Is there a way to lock a file using PHP in a way that Perl will respect? It looks like the flock() function is PHP specific.