我有一个运行外部进程的PHP脚本。Lighttpd缓存shell_exec()输出?
外部进程输出一个JSON字符串,其中包含系统中的数据,该数据会随时更改。
当我运行外部进程时,我可以清楚地看到JSON字符串是每次运行它时都不相同的 。
但是,当我从Web浏览器使用AJAX调用我的PHP脚本时,首次调用PHP脚本后JSON字符串不会更新。
JSON字符串被更新的唯一时间是当我在网站内部时刷新页面或手动运行外部过程。
这究竟是为什么?
LIGHTTPD缓存输出吗?
编辑:
,这里是我的lighttpd配置文件的内容:
server.modules = (
"mod_access",
"mod_cgi",
"mod_alias",
"mod_compress",
"mod_redirect",
# "mod_rewrite",
)
server.document-root = "/var/www"
server.upload-dirs = ("/var/cache/lighttpd/uploads")
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
index-file.names = ("index.php", "index.html", "index.lighttpd.html")
url.access-deny = ("~", ".inc")
static-file.exclude-extensions = (".php", ".pl", ".fcgi")
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ("application/javascript", "text/css", "text/html", "text/plain")
# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
$HTTP["url"] =~ "/cgi-bin/" {
cgi.assign = ("" => "")
}
cgi.assign = (
".cgi" => ""
)
编辑
According to the following Google Product thread一个人叫johnjbarton
提到了以下几点:
好吧,我与Chrome缓存专家交谈。在我的情况的问题是非常 这个错误可能描述:错误30862 - 动态插入 子资源不重新验证,即使在包含文档是 重载https://bugs.webkit.org/show_bug.cgi?id=30862
的力,刷新外部页面加载仅军队资源。它 不强制刷新XHR加载的资源。这是一个dojo应用程序中的所有资源的几乎 。
当我看着铬的控制台下Network
部分,它说 所有我的网站提出的要求是XHR
类型。
这可以以某种方式相关吗?
编辑
我的请求标头是
Accept */*
Content-Type application/x-www-form-urlencoded
非常重要的编辑 我编辑我的PHP脚本,使其追加的结果处理它执行到一个日志文件。
事实证明,过程的输出总是相同的。
但是,当我手动运行该过程时,它会不断按预期更改。
在我看来好像LIGHTTPD缓存它执行的进程的输出。
编辑
这是我的PHP脚本的样子:?
<?php
session_start();
if(!isset($_SESSION['user'])){
header("Location: /");
} else {
header('Content-type: application/json');
$output = shell_exec('/home/debian/myProcess/myProcess');
file_put_contents("/var/log/lighttpd/access.log", $output, FILE_APPEND | LOCK_EX);
echo $output;
}
>
你能发布lighttpd配置的相关部分吗? – Will
在浏览器中检查进行AJAX调用时的网络流量,很可能会将结果缓存在浏览器中。使用任何用于AJAX的JS框架来检查如何避免缓存AJAX响应,如果不使用框架,则必须为每个查询网址添加时间戳。 – Eborbob
@Eborbob哦,好的。那么,如何添加时间戳以及在哪里添加此时间戳?我是否将其添加到客户端或服务器端?你对我在哪里可以阅读更多关于这方面的建议有什么建议吗?最后:为什么时间戳会改变浏览器缓存的行为? – vaid