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 7278885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:56:12+00:00 2026-05-28T22:56:12+00:00

I have some simple text file. I am trying to read that file contents

  • 0

I have some simple text file. I am trying to read that file contents using PHP and update it to the user. I was setting up the ajax request for every 2 seconds but the problem is the file won’t be updated for every 2 seconds may be 15 or 30 or 1 minute long.

So I thought of doing this: check the last modified time of file and if it is different then only update it to the user but here where I am stuck.

JavaScript functions:

 function read()
 {
    read_text();
    t=setTimeout("read()",200);
 }

 function read_text()
 {
     var xmlhttp;
     if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
     }
     else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
       {
          document.getElementById('read').innerHTML = xmlhttp.responseText;
       } 
    }
    xmlhttp.open("GET","demo.php",true);
    xmlhttp.send();
 }

My PHP file:

<?php 
    $a = fileattime("filenam");
    $b = fileattime("filenam");
    if($b > $a )
    {
     echo "update contents";
     $a = $ b;
    }

?>

I thought to store the last modified time of file in $a variable and compare the value with $b variable but here $a will be overwritten with the new value for every ajax request. I want $a to be assigned a value only once, I mean for the first ajax request then later on compare it with $b value and if $b is greater than $a then update the contents to user then fill up $a with $b.

What can I try next?

  • 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-28T22:56:13+00:00Added an answer on May 28, 2026 at 10:56 pm

    Try creating a session, and storing the information in a session variable.

    https://www.php.net/manual/en/reserved.variables.session.php

    If you do that, you’ll have a persistent value that you can use to test against to see the last modified / updated value.

    Be sure to do session_start() at the beginning of the script.

    You can have it look something like this..
    JS:

    // standard Ajax stuff
    xmlhttp.open("GET", "demo.php?request=1", true);
    xmlhttp.send();
    

    PHP:

    <?php
        session_start();
        if($_GET['request'] == 1) $_SESSION['modified_since'] = fileattime('filename');
        $a = $_SESSION['modified_since'];
        $b = fileattime("filename");
        if($b > $a) {
            echo "Update Contents";
            $_SESSION['modified_since'] = $b;
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WPF (XAML) file that has some animated shapes and text.
I have a text file with some data in it, and I'm trying to
I'm trying to read some large text files (between 50M-200M), doing simple text replacement
I am trying to create simple user registration form. I have an index.html file
I have HTML + CSS text. I need some lib with simple function like
I have simple list: <ul> <li>some text 1 </li> <li>some text 2</li> <li>some text
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have some simple shell scripting tasks that I want to do For example:
I have some very simple javascript code that looks like this: var newWindow =
I am trying to create a simple batch file that will replace a line

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.