Red*_*Red 3 php codeigniter output-buffering
我正在尝试在页面/连接关闭后继续PHP脚本.
用户将每1小时POLL脚本,我想返回一些json输出,并希望在后台继续脚本.我使用共享主机,我不能使用cron作业.
这是我尝试过的.
ob_start();
ignore_user_abort();
echo "JSON_OUTPUT GOES HERE";
$ob_length = ob_get_length();
header("Content-Type : text/plain",TRUE);
header("Content-Length : $ob_length",TRUE);
header("Connection : Close",TRUE);
flush();
ob_flush();
ob_end_flush();
sleep(3);
echo "You cant see me..";
exit();
Run Code Online (Sandbox Code Playgroud)
我正在使用Codeigniter框架,但它不能在我的实时服务器上运行.它等待3秒然后输出You cant see me...
请帮我.
项目托管在LINUX/WINDOWS/WAMP-SERVER共享主机中.
Red*_*Red 10
经过一些研究,我得到了它的工作,有时它可能对其他人有用.
function closeOutput($stringToOutput){
set_time_limit(0);
ignore_user_abort(true);
header("Connection: close\r\n");
header("Content-Encoding: none\r\n");
ob_start();
echo $stringToOutput;
$size = ob_get_length();
header("Content-Length: $size",TRUE);
ob_end_flush();
ob_flush();
flush();
}
Run Code Online (Sandbox Code Playgroud)
你可以像使用它一样
$outputContent = 'Contentent Goes Here...';
closeOutput( $outputContent );
sleep(5);
//do some background works ...
exit();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4658 次 |
| 最近记录: |