【问题标题】:PHP-FPM long polling configurationPHP-FPM长轮询配置
【发布时间】:2018-10-19 20:28:31
【问题描述】:

假设我对php-fpm有以下配置:

pm = dynamic
pm.start_servers = 10
pm.max_children = 400
pm.min_spare_servers = 8
pm.max_spare_servers = 16
pm.process_idle_timeout = 10s

我们还假设每个用户必须有无休止的长轮询请求。如果我有 10000 多个请求的限制,并且我有 10000 个用户连接到我的网站,这是否意味着我的服务器将永远挂起?

另一个问题:serverschildrensimultaneous requests 有什么关系?每个请求都会产生一个新进程吗? serverschildren 有什么区别?据我了解,children 是进程。

PS:请不要推荐 Websockets 或任何其他技术。

谢谢。

【问题讨论】:

    标签: php fpm


    【解决方案1】:

    当您将 PHP-FPM 与动态进程(这是默认值和推荐值)一起使用时,您有以下选择:

    ; Choose how the process manager will control the number of child processes.
    ; Possible Values:
    ;   static  - a fixed number (pm.max_children) of child processes;
    ;   dynamic - the number of child processes are set dynamically based on the
    ;             following directives:
    ;             pm.max_children      - the maximum number of children that can
    ;                                    be alive at the same time.
    ;             pm.start_servers     - the number of children created on startup.
    ;             pm.min_spare_servers - the minimum number of children in 'idle'
    ;                                    state (waiting to process). If the number
    ;                                    of 'idle' processes is less than this
    ;                                    number then some children will be created.
    ;             pm.max_spare_servers - the maximum number of children in 'idle'
    ;                                    state (waiting to process). If the number
    ;                                    of 'idle' processes is greater than this
    ;                                    number then some children will be killed.
    ; Note: This value is mandatory.
    

    响应您的问题,服务器和子进程是进程,每个进程将响应一个用户。您的服务器将支持最多 400 个并发连接。

    我已经用长轮询实现了很多系统,它比在某个时间间隔刷新更有效并且使用更少的资源。

    最大的问题是你的 PHP 进程会消耗你所有的服务器内存,我强烈建议你寻找任何替代方案。

    我使用的一个很好的替代方案是NGiNX HTTP Server Push module,您可以创建将信息推送给您的客户的脚本。使用这种方法,您可以扩展到数千个并发客户端,这是直接使用 PHP 无法完成的。

    例如,我做了一个电子邮件客户端,它有一个用 PHP 编写的守护程序,它使用这个 NGiNX 模块监控用户邮箱并推送新电子邮件的通知,并且使用PHP inotify 完成文件系统监控,在其他换句话说,我使用几乎 0 的系统资源并创建了一个具有实时通知和非常低的网络和处理器使用率的 web 邮件系统,仅使用 PHP 和长轮询或使用刷新的计算成本很高。

    我知道您不想要 Websockets 建议,但根据您的需求,它几乎无法避免。

    【讨论】:

    • 所以基本上serverschildren 是完全一样的吗?谢谢你的建议!你认为有可能有一个最佳的php-fpm 配置来避免直接使用NGiNX 吗?我们的NGiNX 配置文件是固定的,我们不会经常更改它,这不是一件容易的事。
    • 是的,您可以阅读“服务器”,其中的“孩子”。看看这篇文章 (if-not-true-then-false.com/2011/…),它将为您提供 NGiNX 和 PHP-FPM 优化的一个很好的概述。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 2011-09-19
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多