-2

I have a .txt file located under some folder of my data files. Now I have created a long polling system (actually copied the code ) which is run by ajax. Now the problem is that my php script is unable to fetch file modification time of the text file (it totally disregards the file).

Below I have both the original code of the author and my twerked code. The one of the author worked fine, but not mine. Plz help.

The apache server is hosted on windows server

THe file path is absolutly correct and file exist.

Here's the section of my code which has error

    while (true) {
    //**The error occurs here**
    $fileModifyTime = filectime($file);

    if ($fileModifyTime === false) {
        throw new Exception('Could not read last modification time');
    }

    // if the last modification time of the file is greater than the last update sent to the browser...
    if ($fileModifyTime > $lastUpdate) {
        setcookie('lastUpdate', $fileModifyTime);

  require 'msgread.php';
  // get file contents from last lines...
  $fileRead = tailCustom($file, 8);

        exit(json_encode([
            'status' => true,
            'time' => $fileModifyTime,
            'content' => $fileRead
        ]));

    }

    // to clear cache
    clearstatcache();

    // to sleep
    sleep(1);

}

here's the original code from where i copied the author's original polling code

and here's my full code, just in case needed My script which has error

amankrokx
  • 52
  • 5

1 Answers1

0

I suspect that your problem is that file.txt does not exist. have you created it and ensured that it's in the current working directory of the script?

It's impossible to say more without seeing your actual code. If you select it and press Ctrl + K that will indent it all.

wizzwizz4
  • 6,140
  • 2
  • 26
  • 62