【发布时间】:2014-06-12 22:11:00
【问题描述】:
我无法在 FCGI 模式下理解和运行简单的 PHP 脚本。我正在学习 Perl 和 PHP,我得到了下面的 Perl 版本的 FastCGI 示例,可以按预期工作。
Perl FastCGI 计数器:
#!/usr/bin/perl
use FCGI;
$count = 0;
while (FCGI::accept() >= 0) {
print("Content-type: text/html\r\n\r\n",
"<title>FastCGI Hello! (Perl)</title>\n",
"<h1>FastCGI Hello! (Perl)</h1>\n",
"Request number ", $++count,
" running on host <i>$ENV('SERVER_NAME')</i>");
}
在 PHP 中搜索类似内容时发现谈论“fastcgi_finish_request”,但不知道如何 为了在 PHP 中完成反例,这是我尝试过的:
<?php
header("content-type: text/html");
$counter++;
echo "Counter: $counter ";
//http://www.php.net/manual/en/intro.fpm.php
fastcgi_finish_request(); //If you remove this line, then you will see that the browser has to wait 5 seconds
sleep(5);
?>
【问题讨论】:
-
简短回答:你不能使用 PHP,它不允许你像 Perl 那样访问 FCGI 状态。您必须以原子方式在请求之间存储
$count,例如通过数据库查询更新 + 1,同时提前获取结果并执行 $count + 1 仅出于显示原因。
标签: php perl fastcgi mod-fcgid