如何使用fastcgi_finish_request()的示例 [英] example of how to use fastcgi_finish_request()

查看:338
本文介绍了如何使用fastcgi_finish_request()的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以举一个简单的例子来说明如何使用fastcgi_finish_request()函数吗? 我用谷歌搜索,但只发现了一些通用的提法,有人说他们成功地使用了它,但是我找不到一个带有代码的例子.

Can someone show a simple example on how to use fastcgi_finish_request() function? I googled but only found some general mention of it, some people say they use it successfully but I could not find a single example with code.

例如,我有一个PHP对象.要将响应发送到浏览器,请生成HTML,然后 通过getResult()返回它.然后回显结果.

For example, I have a PHP object. To send a response to a browser I generate HTML, then returning it via getResult(). Then echo the result.

像这样:

$obj = new controller();
echo $o->getResult();

假设我想利用这种优化技术将结果发送到浏览器,然后完成一些潜在的漫长过程,例如连接到某些API(例如Facebook API).

Let's say I want to take advantage of this optimization technique to send result to browser and then finish up some potentially long process like connecting to some API, like maybe Facebook API.

我将如何去做?我了解基本上可以调用fastcgi_finish_request();然后继续执行php脚本.

How would I go about doing this? I understand that basically I can call fastcgi_finish_request(); and then continue executing php script.

我只需要看示例代码,我不够聪明,无法自己解决这个问题.

I just need to see example code, I'm not smart enough to figure it out by myself.

推荐答案

我了解基本上可以调用fastcgi_finish_request();然后继续执行PHP脚本.

I understand that basically I can call fastcgi_finish_request(); and then continue executing PHP script.

是的,这就是您要做的一切.

Yes, that's all you have to do.

$obj = new controller();
echo $o->getResult();
fastcgi_finish_request();
do_facebook_thing();

要说服自己正在运行,请执行以下操作:

To convince yourself it is working, do this:

echo "Test";
fastcgi_finish_request();
sleep(10);

如果您删除第二行,那么您将看到浏览器必须等待10秒.

If you remove the second line, then you will see that the browser has to wait 10 seconds.

这篇关于如何使用fastcgi_finish_request()的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆