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

  • 相关阅读:
    ThinkingInJava对this关键字的介绍
    MYSQL(三)
    MySQL(二)
    mysql语句实战
    js事件委托
    Python中应该使用%还是format来格式化字符串?
    js高级知识---词法分析和AO 链
    lsof/netstat命令的一个重要作用: 根据进程查端口, 根据端口查进程
    gg
    io多路复用
  • 原文地址:https://www.cnblogs.com/sky20081816/p/3125986.html
Copyright © 2020-2023  润新知