【发布时间】: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