Jump to content

Recommended Posts

Hello,

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.

<?php
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!';
exit;
}

 

Link to comment
https://forums.phpfreaks.com/topic/316048-read-txt-file-only-if-its-complete/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.