Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:16:08+00:00 2026-05-26T20:16:08+00:00

I am using PHP to read in a .txt file, and parsing the data

  • 0

I am using PHP to read in a .txt file, and parsing the data to a webpage. The .txt file is a local log file that displays my server’s status, and I can currently read out the last line and push it out to my site.

However, when my server’s status changes, the .txt file becomes updated locally, but the new value never shows up on the site.

I am using HTML5/Javascript for displaying the contents, and PHP for reading the file and parsing/cleaning up the input. The code segment I am attaching, which shows the PHP file reading functions I am using, runs every 10 seconds. After this segment is run, the display (I am using an HTML5 canvas) is refreshed, but the data stays constant. The display only updates if I manually refresh the page.

Is it possible that to poll this txt file every 10 seconds or so, and push the last line out into a variable I can call?

function getCurrentStatus() {
    <?php           
        clearstatcache();

        $myFile = "C:\available.log";

        $fh = fopen($myFile, 'r');
        $theData = fread($fh, filesize($myFile));
        fclose($fh);

        $statusList = explode("\n", $theData);
        $statusListLength = count($statusList) - 2;
        $currentStatus = explode(" ", $statusList[$statusListLength]);
        $previousStatus = explode(" ", $statusList[$statusListLength - 1]);

        $myFile = "C:\std_server0.out";

        $fh = fopen($myFile, 'r');
        $theData = fread($fh, filesize($myFile));
        fclose($fh);

        $garbageCollector = array_map('trim',explode("\n", $theData));
        $garbageCollectorLength = count($garbageCollector);
    ?>
    currentStatus = ["Latest Status:", "<?php echo $currentStatus[0]; ?>", "First Started:", "<?php echo $currentStatus[1]; ?>", "<?php echo $currentStatus[2]; ?>", "Last Checked:", "<?php echo $currentStatus[4]; ?>", "<?php echo $currentStatus[5]; ?>"];      

    latestGC = "<?php echo $garbageCollector[$garbageCollectorLength - 2] ?>"
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:16:08+00:00Added an answer on May 26, 2026 at 8:16 pm

    The reason this isn’t working is because JavaScript is executed in the client’s browser, where the PHP is executed on the server. So in the initial load, you’re getting what you’d expect because as the page was being created, PHP got the contents of that file. After that, however, PHP is gone and out of the picture.

    You’ll probably need to look into using AJAX to periodically refresh the contents.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using Fast CGI I can't get it to read the php.ini file. See my
Using PHP, it's possible to read off the contents of a file using fopen
I am trying to read some settings from php.ini using zend. The API that
Using PHP, I can convert MySQL data or static table data to csv, Excel,
Is it possible/how can I open a text file in PHP using a file
I'm using PHP's cURL function to read profiles from steampowered.com. The data retrieved is
I have read the following tutorial Uploading Files To the Server Using PHP and
Let say i want to read a text file using php. Now my text
I want to open and read an XML file using php, but I wont
I'm using PHP to read if an entry in my table on the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.