Lighttpd 缓存 shell_exec() 输出?

Lighttpd caching shell_exec() output?

我有一个 PHP 脚本,它 运行 是一个外部进程。

外部进程输出一个 JSON 字符串,其中包含来自系统的数据,这些数据不时发生变化。

当我运行外部进程时我可以清楚地看到JSON字符串是 我每次都不一样 运行 它。

但是,当我从 Web 浏览器使用 AJAX 调用我的 PHP 脚本时,JSON 字符串在第一次调用 PHP 脚本后不会更新。

唯一一次更新 JSON 字符串是在我刷新页面或 运行 在网站内部时手动执行外部进程时。

为什么会这样?

LIGHTPD 是否缓存输出?

编辑:

这是我的 LIGHTPD 配置文件内容:

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 的人提到了以下内容:

Ok I spoke with a Chrome cache expert. The problem in my case is very likely described on this bug: Bug 30862 - Dynamically inserted subresources aren't revalidated even when the containing document is reloaded https://bugs.webkit.org/show_bug.cgi?id=30862

The force-refresh only forces resource loaded in the outer page. It does not force refresh on XHR loaded resources. Which is pretty much all of the resources in a dojo app.

当我在 Network 部分下查看 chrome 的控制台时,它说 我的网站发出的所有请求都是 XHR.

类型

这会不会有某种关联?

编辑

我要求的headers是

Accept */*

Content-Type application/x-www-form-urlencoded

非常重要的编辑 我编辑了我的 PHP 脚本,以便将它执行的过程的结果附加到日志文件中。

事实证明,过程的输出总是相同的。

然而,当我 运行 手动处理过程时,它会按预期不断变化。

在我看来,LIGHTPD 正在缓存它执行的进程的输出。

编辑

这是我的 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;
}

?>

好的,所以我找到了问题的原因。

我正在执行的进程,我称之为 myProcess 运行 进程本身称为 iwlist

iwlist 似乎需要 运行 作为 root。

由于我的 PHP 脚本执行 ANY 进程作为名为 www-data 的 LIGHTPD 服务器用户,进程 myProcess 将作为 www-data 反过来又尝试将 iwlist 作为 www-data 执行,这就是它全部失败的地方。

我的解决方案是 运行 myProcess 通过守护进程将 myProcess 的输出转储到我的 PHP 脚本可以读取的文件中。

这非常有效。 `