zoukankan      html  css  js  c++  java
  • 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要注意

  • 相关阅读:
    用Sqoop实现数据HDFS到mysql到Hive
    hdfs的文件结构
    搭建Hadoop-1.2.1&hbase-0.94.17&hive-0.9.0&centos6.8_x64集群
    缩减表空间碎片
    MySQL8.0.12源码编译安装_centos7.3
    Mysql8.0.18的源码安装
    mysql5.7.31二进制安装_centos7
    个人windows开发环境风格
    linux shell中那些奇奇怪怪的语法
    关于上线的一些事儿
  • 原文地址:https://www.cnblogs.com/sky20081816/p/3125986.html
Copyright © 2011-2022 走看看