我想运行这个脚本:
<?php
$file = file_get_contents('data.json');
echo ($file);
unset($file);
exit(0);
?>
如果我在 JS 中通过 ajax 访问此脚本,则没有问题,但如果我使用 php script.php
或 php -f script.php
在我的服务器 shell 上运行此脚本code> 始终显示此 JSON 字符串的旧版本。通过 ajax,我总是从该脚本收到最新的数据。
最后,我需要将此脚本包含在另一个 php 脚本中,该脚本运行一个循环来检测更改。这也没有收到最新的数据。
最佳答案
试试这个:
<?php
$file = file_get_contents( __DIR__ . DIRECTORY_SEPARATOR .'data.json');
echo ($file);
unset($file);
exit(0);
?>
data.json 应与您的 php 文件位于同一目录中。
关于javascript - PHP 脚本未在服务器 shell 上显示正确的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38982849/