【发布时间】:2012-05-03 21:44:54
【问题描述】:
使用 PHP 和 Apache,是否可以在接收到标头之后但在发送正文之前启动 PHP 脚本?
我的意思是这样的:
PUT /sync/testStream.php HTTP/1.1
Host: localhost
User-Agent: test
Content-Length: 500
Content-Type: text/plain
<start the script here>
hello
this is a test
目标是在脚本期间锁定文件(实际上是在上传期间)。
我尝试从 php://input 读取,但没有成功:脚本仅在收到整个正文时启动。
这是我的脚本:
<?php
echo "Hello. Start sending data.";
ob_flush();
$file = fopen('php://input', 'r');
if ($file === false) {
die("Could not open php://input");
}
while (($line = fgets($file)) !== false) {
echo $line;
}
echo "Bye";
欢迎任何提示!
【问题讨论】:
-
你能澄清你的问题吗? PHP 通常在发送标头之前由 Web 服务器启动。