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要注意

  • 相关阅读:
    PDB文件详解
    C++模板常用功能讲解
    Windows下多线程编程(二)
    关于静态库中使用全局变量可能导致的问题
    js中的函数
    js中字符串的加密base64
    列表推导式
    函数和方法的区别
    xshell连不上虚拟机
    网络编程,并行,并发和协程
  • 原文地址:https://www.cnblogs.com/sky20081816/p/3125986.html
Copyright © 2011-2022 走看看