【php】php-fpm的中断和启动控制
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【php】php-fpm的中断和启动控制,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3314字,纯文字阅读大概需要5分钟。
内容图文
![【php】php-fpm的中断和启动控制](/upload/InfoBanner/zyjiaocheng/757/6b96c60c98e3449091a3189d36cec7f6.jpg)
php-fpm,如何控制访问特别长的请求?是否有中断的机制?
max_execute_time(php.ini): 这个是用户态时间,不累计io操作,但是大多数操作都是io会慢,所以这个参数只能适用于cpu密集型,大部分应用不适合;
request_terminate_timeout(php-fpm): 这个是request整个处理超时,是计算io操作的,
request_terminate_timeout,设置为5s,超过这个时间点,php进程结束,然后给客户端返回502.
php-fpm对于这两种设置的处理都是直接kill掉进程,再启动一个新的worker进程,整个操作代价是比较高的,但是重启有个好处是内存不会被不断消耗,即使有小部分泄漏都没事。
需要注意的是:max_execute_time是php.ini中设置的,request_terminate_timeout是php-fpm中设置的。
https://www.kancloud.cn/nickbai/php7/363357
另外,如果想解决这种超时问题,业务层面的php代码优化,接口优化才是处理超时的最终解决方案。
二,其他php-fpm参数
; 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. With this process management, there will be ; always at least 1 children. ; 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. pm = dynamic pm.max_children = 5 pm.min_spare_servers = 1 pm.max_spare_servers = 2 ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 pm.max_requests = 500 ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 5
pm相关的参数,都是和进程管理相关的。
pm=dynamic表示进程数是动态生成。
pm.max_children 表示允许生成的最大子进程数
pm.min_spare_children 表示最小的空闲子进程
pm.max_spare_children 表示最大的空闲子进程
pm.max_requests = 500; 整个代表的是每个子进程在重新生成之前要处理多少个请求数。这个对于内存泄漏有很好的抑制作用。
也就是说子进程在处理到500个请求时候一定会重新生成。
php-fpm,默认在处理多个并发请求时,如果当前进程不够用时,最多能开到max_children个子进程数。
但是这些临时生成的子进程,并不是请求完毕就会释放,而是得等到因为某些原因需要退出时才会退出。
常见的有两个原因:
A,设定了pm.max_requests参数,那么处理了这么多请求一定会退出;
B,如设定了request_terminate_timeout,一个请求超过了这个限定,该对应的php-fpm子进程也会被kill掉。
内容总结
以上是互联网集市为您收集整理的【php】php-fpm的中断和启动控制全部内容,希望文章能够帮你解决【php】php-fpm的中断和启动控制所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。