Determine if a txt file is done being updated/written to?

I have an EXE app on my home server that uploads a .txt file (live lightning strikes) every 1 minute to my web server. Then I use this PHP code to read the text file and load it into their software (like Google Earth) where it displays it visually on the map. I’m using PHP to hide public view of strikes(us).txt file as they will scrape the data.

My issue is, sometimes the software calls the PHP file which reads the .txt file and it’s still being written to, not fully complete, which fails in the software. How can I use PHP to determine if this file is not open, being written to, or incomplete and either wait 2 seconds and try again or something alike. Thank you for any help.

header('Content-Type: text/plain');

if (preg_match('/(GRLevel2|GRLevel3|GR2Analyst)/', $_SERVER['HTTP_USER_AGENT'])) {
echo file_get_contents( "Strikes(US).txt" );
} else {
echo 'Please Copy & Paste the URL directly into your GRLevelX Placefile Manager!';

Sponsor our Newsletter | Privacy Policy | Terms of Service