如何使用 fastcgi_finish_request() 的示例
有人可以展示一个如何使用 fastcgi_finish_request()
函数的简单示例吗? 我用谷歌搜索,但只发现了一些一般性的提及,有些人说他们成功地使用了它,但我找不到带有代码的单个示例。
例如,我有一个 PHP 对象。为了向浏览器发送响应,我生成 HTML,然后 通过 getResult() 返回它。然后回显结果。
像这样:
$obj = new controller();
echo $o->getResult();
假设我想利用这种优化技术将结果发送到浏览器,然后完成一些可能很长的过程,例如连接到某些 API,例如 Facebook API。
我该怎么做呢?我知道基本上我可以调用 fastcgi_finish_request();
然后继续执行 php 脚本。
我只需要查看示例代码,我不够聪明,无法自己弄清楚。
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.
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.
Like this:
$obj = new controller();
echo $o->getResult();
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这就是你所要做的。
要说服自己它正在工作,请执行以下操作:
如果删除第二行,那么您将看到浏览器必须等待 10 秒。
Yes, that's all you have to do.
To convince yourself it is working, do this:
If you remove the second line, then you will see that the browser has to wait 10 seconds.