【问题标题】:The filemtime () isn't working for my script, but is working fine for the script where I copied the example codefilemtime () 不适用于我的脚本,但适用于我复制示例代码的脚本
【发布时间】:2018-07-02 06:38:26
【问题描述】:

我的数据文件的某个文件夹下有一个 .txt 文件。现在我创建了一个由 ajax 运行的长轮询系统(实际上是复制了代码)。 现在的问题是我的 php 脚本无法获取文本文件的文件修改时间(它完全忽略了文件)。

下面我有作者的原始代码和我的 twerked 代码。作者之一工作得很好,但不是我的。 请帮忙。

apache 服务器托管在 windows 服务器上

文件路径绝对正确,文件存在。

这是我的代码中有错误的部分

    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);

}

这是我复制的原始代码 the author's original polling code

这是我的完整代码,以备不时之需 My script which has error

【问题讨论】:

  • 您不能直接链接到 PHP 文件,除非您禁用该目录的解释器。还请添加有关您的操作系统(和服务器的操作系统)的信息。
  • ????对不起我的错误,我只是在镜像站点上托管它。
  • @AmanKumar 我在移动设备上,所以除非您将文件放在页面上,否则我无法帮助您;我的 iPear 拒绝打开文件。
  • 哦!我也在移动设备上。
  • 好的,等一下,我在试试

标签: php ajax long-polling filemtime


【解决方案1】:

我怀疑你的问题是file.txt 不存在。您是否已创建它并确保它位于脚本的当前工作目录中?

如果没有看到您的实际代码,就不可能说更多。如果您选择它并按 Ctrl + K 将全部缩进。

【讨论】:

  • 抱歉问题安排不当。我已经编辑了它们,请看一下
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-12
  • 1970-01-01
  • 1970-01-01
  • 2017-03-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多