{"id":553809,"date":"2022-02-02T14:08:48","date_gmt":"2022-02-02T06:08:48","guid":{"rendered":"http:\/\/4563.org\/?p=553809"},"modified":"2022-02-02T14:08:48","modified_gmt":"2022-02-02T06:08:48","slug":"%e5%85%b3%e4%ba%8e%e8%bf%9b%e7%a8%8b%e5%92%8c-php-fpm-%e7%9a%84%e4%b8%80%e4%ba%9b%e7%96%91%e6%83%91-7","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=553809","title":{"rendered":"\u5173\u4e8e\u8fdb\u7a0b\u548c PHP -fpm \u7684\u4e00\u4e9b\u7591\u60d1"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> \u5173\u4e8e\u8fdb\u7a0b\u548c PHP -fpm \u7684\u4e00\u4e9b\u7591\u60d1 <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : palemoky <\/span>  <span><i><\/i> 35<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u5728\u770b CSAPP \uff0c\u770b\u5230\u8fdb\u7a0b\u90e8\u5206\uff0c\u7ed3\u5408\u4e4b\u524d\u7684 PHP \u5b66\u4e60\uff0c\u6709\u4e00\u4e9b\u95ee\u9898\u8bf7\u6559\u4e0b\u5404\u4f4d V \u53cb\uff1a<\/p>\n<ol>\n<li> \u901a\u8fc7 <code>pstree 32765 -np<\/code> \u53ef\u4ee5\u770b\u5230 fpm \u7684\u8fdb\u7a0b\u7ed3\u6784\u5982\u4e0b\u56fe\uff0c\u8fd9\u91cc\u7684\u7236\u8fdb\u7a0b\uff08 32765 \uff09\u5728 fork \u4e86\u5b50\u8fdb\u7a0b\u540e\uff0c\u8fd8\u4f1a\u5904\u7406\u8bf7\u6c42\u5417\uff1f\u8fd8\u662f\u53ea\u8d1f\u8d23\u7ba1\u7406\u5b50\u8fdb\u7a0b\uff1f\n<pre><code>php-fpm(32765)\u2500\u252c\u2500php-fpm(508)                \u251c\u2500php-fpm(2527)                \u2514\u2500php-fpm(3344) <\/code><\/pre>\n<\/li>\n<li>\u5b50\u8fdb\u7a0b\u5728\u5904\u7406\u5b8c\u4e00\u4e2a\u8bf7\u6c42\u540e\u4f1a\u9000\u51fa\u5417\uff1f fpm \u9664\u4e86\u5728\u8fbe\u5230 <code>pm.max_requests<\/code> \u548c <code>pm.process_idle_timeout<\/code> \u7684\u9884\u8bbe\u503c\u9000\u51fa\u5916\uff0c\u8fd8\u4f1a\u5728\u4ec0\u4e48\u673a\u5236\u4e0b\u9000\u51fa\u5462\uff1f fpm \u7684\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u4f1a\u5728\u4e00\u4e2a\u8bf7\u6c42\u751f\u547d\u5468\u671f\u7ed3\u675f\u540e\u5904\u7406\u65b0\u7684\u8bf7\u6c42\u5417\uff1f<\/li>\n<li>\u5e38\u8bf4\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5c31\u662f\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u50cf Nginx \u6216 php-fpm \u53c8\u4f1a fork \u591a\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u90a3\u6b64\u65f6\u7684 Nginx \u548c PHP \u662f\u6709\u51e0\u4e2a\u8fdb\u7a0b\u5462\uff1f 1 \u4e2a\u5417\uff1f\u56e0\u4e3a\u5b50\u8fdb\u7a0b\u90fd\u7531\u7236\u8fdb\u7a0b\u7ba1\u7406\uff1f<\/li>\n<li>\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u6709\u72ec\u7acb\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\uff0c \u6211\u770b\u9ed8\u8ba4\u5927\u5c0f\u662f 1024 \uff0c\u5982\u679c\u4e00\u4e2a\u8bf7\u6c42\u4f9d\u8d56\u6253\u5f00\u8d85\u8fc7 1024 \u4e2a\u8d44\u6e90\uff0c\u90a3\u662f\u4e0d\u662f\u8fd9\u4e2a\u8bf7\u6c42\u5c31\u65e0\u6cd5\u6b63\u5e38\u5904\u7406\u4e86\u5462\uff1f<\/li>\n<li>\u5f53 fpm \u901a\u8fc7 tcp \u7684\u65b9\u5f0f\u4e0e Nginx \u901a\u4fe1\u65f6\uff0c\u9ed8\u8ba4\u7684 fpm \u7aef\u53e3\u662f 9000 \uff0c\u4e0d\u540c\u7684\u5b50\u8fdb\u7a0b\u662f\u5982\u4f55\u90fd\u901a\u8fc7 9000 \u548c Nginx \u901a\u4fe1\u7684\u5462\uff1f\u8fd8\u662f\u5b50\u8fdb\u7a0b\u6709\u4e0d\u540c\u7684\u7aef\u53e3\u5462\uff1f<\/li>\n<\/ol><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"7071143\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> 3 \u5e38\u8bf4\u7684\u4e0d\u5bf9<br \/>4 \u8981\u770b limit \uff0c\u8fbe\u5230\u4e86\u5c31\u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\u4e86<br \/>5 \u56de\u53bb\u5b66\u7f51\u7edc\u5427\uff0c\u8fd9\u662f\u4e00\u4e2a\u5e38\u89c1\u9519\u8bef\u7406\u89e3 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7071144\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mahone3297 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> 1. \u5e94\u8be5\u662f\u8981 accept \u8bf7\u6c42\uff0c\u7136\u540e fork \u5176\u4ed6\u5b50\u8fdb\u7a0b<br \/>2. \u5e94\u8be5\u4e0d\u4f1a\u9000\u51fa\uff0c\u7b49\u5f85\u5904\u7406\u65b0\u8bf7\u6c42\u3002\u9664\u4e86\u8fbe\u5230\u4f60\u8bf4\u7684 pm.max_requests \u548c pm.process_idle_timeout \u7b49\u8bbe\u7f6e<br \/>3. \u5f88\u591a\u4e2a\u8fdb\u7a0b<br \/>4. \u5e94\u8be5\u4f1a\u62a5\u9519 too many open files<br \/>5. \u53ef\u80fd @julyclyde \u7684\u610f\u601d\u662f\u5b50\u8fdb\u7a0b\u6709\u4e0d\u540c\u7684\u7aef\u53e3\uff1f\u8bf7\u6559\u4e0b @julyclyde \u8fd9\u91cc\uff0c\u5b50\u8fdb\u7a0b\u662f\u76f4\u63a5\u8ddf nginx \u901a\u4fe1\u7684\u662f\u5427\uff1f <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7071145\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @mahone3297 <br \/>1 php-fpm \u662f\u63d0\u524d fork \u597d\u7684 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7071146\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mkfs <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> FPM \u6709\u597d\u51e0\u79cd\u8fdb\u7a0b\u7ba1\u7406\u6a21\u5f0f\u7684\uff0c\u4e0d\u540c\u7b56\u7565\uff0c\u7528\u4e0d\u540c\u7684\u53c2\u6570\u3002<br \/>PHP \u662f\u591a\u8fdb\u7a0b\u6a21\u5f0f\u7684\uff0c\u4e00\u4e2a\u8bf7\u6c42\u4e00\u4e2a\u8fdb\u7a0b\u3002<br \/>max_requests \u53c2\u6570\uff0c\u662f\u5bf9\u4e8e\u90a3\u79cd\uff0c\u8981\u4fdd\u7559\u4e00\u5b9a\u7a7a\u95f2\u8fdb\u7a0b\u7684\u60c5\u51b5\u6765\u8bf4\u7684\uff0c\u56e0\u4e3a PHP \u662f\u8fdb\u7a0b\u6a21\u5f0f\uff0c\u6709\u65b0\u7684\u8bf7\u6c42\uff0c\u5c31\u9700\u8981 fork \u65b0\u8fdb\u7a0b\uff0cfork \u6210\u672c\u6bd4\u8f83\u9ad8\uff0c\u4e3a\u4e86\u63d0\u9ad8\u54cd\u5e94\u901f\u5ea6\uff0c\u5c31\u9884\u5148 fork \u4e00\u4e9b\u8fdb\u7a0b\uff0c\u8fd9\u6837\u6709\u8bf7\u6c42\u8fc7\u6765\uff0c\u5c31\u76f4\u63a5\u7528\u8fd9\u4e9b\u8fdb\u7a0b\u597d\u4e86\u3002\u56e0\u4e3a FPM \u8981\u4e00\u76f4\u4fdd\u8bc1\u5b58\u6709\u4e00\u5b9a\u6570\u91cf\u7684\u8fdb\u7a0b\uff0c\u6240\u4ee5\u53ef\u80fd\u4f1a\u6709\u4e00\u90e8\u5206\u8fdb\u7a0b\uff0c\u4e00\u76f4\u6ca1\u673a\u4f1a\u9000\u51fa\u3002\u90a3\u4e3a\u4ec0\u4e48\u8981\u6709 max_requests \u53c2\u6570\u5462\uff1f\u56e0\u4e3a\u6015\u5185\u5b58\u6cc4\u6f0f\u5457\uff0c\u8d85\u8fc7\u4e00\u5b9a\u6570\u91cf\u7684\u8bf7\u6c42\u540e\uff0c\u9000\u51fa\u8fdb\u7a0b\u91cd\u65b0\u521b\u5efa\uff0c\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<br \/>process_idle_timeout \uff0c\u662f\u4e3a\u4e86\u590d\u7528\u201c\u90a3\u4e9b fork \u51fa\u6765\uff0c\u4f46\u53c8\u4e0d\u51c6\u5907\u957f\u671f\u4fdd\u7559\u7684\u8fdb\u7a0b\u201d\u7684\uff08\u6709\u63a7\u5236\u7a7a\u95f2\u8fdb\u7a0b\u6570\u91cf\u7684\u53c2\u6570\uff0c\u8d85\u8fc7\u8bbe\u5b9a\u6570\u91cf\u7684\u65f6\u5019\uff0c\u4f1a\u6709\u8fdb\u7a0b\u9000\u51fa\uff09\uff0c\u56e0\u4e3a\u4e00\u4e2a\u8bf7\u6c42\u5904\u7406\u5b8c\u6bd5\u540e\uff0c\u53ef\u4ee5\u5148\u4e0d\u9000\u51fa\u8fd9\u4e2a\u8fdb\u7a0b\uff0c\u8ba9\u540e\u5e8f\u5230\u6765\u7684\u8bf7\u6c42\u590d\u7528\u8fd9\u4e2a\u8fdb\u7a0b\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\u6ca1\u80fd\u590d\u7528\uff0c\u5c31\u9000\u51fa\u8fd9\u4e2a\u8fdb\u7a0b\u3002<br \/>Nginx \u662f\u4e8b\u4ef6\u9a71\u52a8\u6a21\u5f0f\uff0c\u6709\u65b0\u7684\u8bf7\u6c42\uff0c\u4e0d\u4f1a\u521b\u5efa\u65b0\u8fdb\u7a0b\uff0c\u4f46\u662f\u4ed6\u4f1a\u8c03\u7528 FPM \uff0cFPM \u4f1a\u521b\u5efa\u65b0\u8fdb\u7a0b\u3002<br \/>\u6587\u4ef6\u63cf\u8ff0\u7b26\u95ee\u9898\uff0c\u8d85\u4e86\uff0c\u518d\u53d1\u8d77\u76f8\u5173\u521b\u5efa\u63cf\u8ff0\u7b26\u7684\u8c03\u7528\uff0c\u4f1a\u62a5\u9519\uff1a&#8221;too many open files&#8221;\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u4f60\u4e00\u4e2a\u8fdb\u7a0b\u4e0d\u9700\u8981\u6253\u5f00\u8fd9\u4e48\u591a\u6587\u4ef6\u5427\uff0c\u51b5\u4e14 PHP \u662f\u591a\u8fdb\u7a0b\u6a21\u5f0f\u3002<br \/>\u7aef\u53e3 9000 \u8fd9\u4e2a\u95ee\u9898\uff0c\u5176\u5b9e\u5c31\u662f TCP \u56db\u5143\u7ec4\u7684\u95ee\u9898\u4e86\uff0c\u670d\u52a1\u5668 IP:\u7aef\u53e3+\u5ba2\u6237\u7aef IP:\u7aef\u53e3\u3002 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7071147\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mkfs <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u670d\u52a1\u5668 IP:\u670d\u52a1\u5668\u7aef\u53e3+\u5ba2\u6237\u7aef IP:\u5ba2\u6237\u7aef\u7aef\u53e3 <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e\u8fdb\u7a0b\u548c PHP -fpm \u7684\u4e00&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/553809"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=553809"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/553809\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=553809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=553809"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=553809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}