我无法在 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);
?>