Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
264 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...