php 伪异步 fastcgi_finish_request

之前我们项目都是用的spawn-cgi的形式管理php的fastcgi,但是发现效率不是很高,这段时间我有空闲就研究下fpm

 

按照我的习惯,我喜欢看官方文档,当我看到这个的时候眼前一亮 

http://php-fpm.org/wiki/Features#request_slowlog_timeout

这玩意是个好东东啊,

This feature allows you to speed up implementation of some php queries. Acceleration is possible when there are actions in the process of script execution that do not affect server response. For example, saving the session in memcached can occur after the page has been formed and passed to a web server. fastcgi_finish_request() is a php feature, that stops the response output. Web server immediately starts to transfer response "slowly and sadly" to the client, and php at the same time can do a lot of useful things in the context of a query, such as saving the session, converting the downloaded video, handling all kinds of statistics, etc.

 

简单来说就是当你的后续工作不影响程序输出的话,可以在程序输出后里面调用 fastcgi_finish_request函数返回结果给client并释放掉client的http链接,但是同时php脚本并没有停止,还是会继续执行后续的工作

 

写个简单的demo

 

浏览器访问可以看到只输出了 “output before func”

而我们 vim /tmp/test.txt的时候赫然发现了 hello,world的字样

但是当我们用命令行调用该文件的时候会发生什么呢?看图

这时候发现fastcgi_finish_request并没有起作用。

 

这个函数当一个伪异步还是蛮不错的,但是只能在php-fpm的环境下运行。非php-fpm要注意

转载于:https://www.cnblogs.com/sky20081816/archive/2013/06/08/3125986.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值