{"id":131757,"date":"2020-07-04T15:53:45","date_gmt":"2020-07-04T07:53:45","guid":{"rendered":"http:\/\/4563.org\/?p=131757"},"modified":"2020-07-04T15:53:45","modified_gmt":"2020-07-04T07:53:45","slug":"php-fpm%e7%9a%84%e5%b8%b8%e7%94%a8%e9%85%8d%e7%bd%ae%e5%92%8c%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=131757","title":{"rendered":"php-fpm\u7684\u5e38\u7528\u914d\u7f6e\u548c\u4f18\u5316"},"content":{"rendered":"<p>\u4e0b\u9762\u5217\u51fa\u914d\u7f6e\u6587\u4ef6php-fpm\u7684\u5404\u79cd\u914d\u7f6e\u4ee5\u53ca\u4e00\u4e9b\u5e38\u89c1\u7684\u4f18\u5316\u3002<\/p>\n<h2><a href=\"https:\/\/www.studytime.xin\/article\/#php-fpm\u7684\u5b89\u88c5\u76ee\u5f55\" title=\"php-fpm\u7684\u5b89\u88c5\u76ee\u5f55\"><\/a>php-fpm\u7684\u5b89\u88c5\u76ee\u5f55<\/h2>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#linux\" title=\"linux\"><\/a>linux<\/h3>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>&#x2F;usr&#x2F;local&#x2F;php&#x2F;php<\/span><br><span>&#x2F;usr&#x2F;local&#x2F;php&#x2F;etc&#x2F;php.ini<\/span><br><span>&#x2F;usr&#x2F;local&#x2F;php&#x2F;sbin&#x2F;php-fpm<\/span><br><span>&#x2F;usr&#x2F;local&#x2F;php&#x2F;etc&#x2F;php-fpm.conf<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#mac\u5e73\u53f0\" title=\"mac\u5e73\u53f0\"><\/a>mac\u5e73\u53f0<\/h3>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>&#x2F;usr&#x2F;bin&#x2F;php<\/span><br><span>&#x2F;etc&#x2F;php.ini<\/span><br><span>&#x2F;usr&#x2F;bin&#x2F;php-fpm<\/span><br><span>&#x2F;etc&#x2F;php-fpm.conf<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h2><a href=\"https:\/\/www.studytime.xin\/article\/#php-fpm\u914d\u7f6e\u8be6\u89e3\" title=\"php-fpm\u914d\u7f6e\u8be6\u89e3\"><\/a>php-fpm\u914d\u7f6e\u8be6\u89e3<\/h2>\n<p>\u8fd9\u662f\u641c\u7d22\u7684\u4e00\u4efd\u8fd8\u7b97\u7b97\u6bd4\u8f83\u8be6\u7ec6\u7684php-fpm.conf\u914d\u7f6e\u8be6\u89e3\uff0c\u6211\u4f1a\u9488\u5bf9\u6027\u7684\u4fee\u6539\u4e0b\uff0c\u5f53\u7136php\u624b\u518c\u4e0a\u4e5f\u6709\u8be6\u7ec6\u7684\u8bb2\u89e3\uff1a<a href=\"http:\/\/php.net\/manual\/zh\/install.fpm.configuration.php\">http:\/\/php.net\/manual\/zh\/install.fpm.configuration.php<\/a><\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><span>10<\/span><br><span>11<\/span><br><span>12<\/span><br><span>13<\/span><br><span>14<\/span><br><span>15<\/span><br><span>16<\/span><br><span>17<\/span><br><span>18<\/span><br><span>19<\/span><br><span>20<\/span><br><span>21<\/span><br><span>22<\/span><br><span>23<\/span><br><span>24<\/span><br><span>25<\/span><br><span>26<\/span><br><span>27<\/span><br><span>28<\/span><br><span>29<\/span><br><span>30<\/span><br><span>31<\/span><br><span>32<\/span><br><span>33<\/span><br><span>34<\/span><br><span>35<\/span><br><span>36<\/span><br><span>37<\/span><br><span>38<\/span><br><span>39<\/span><br><span>40<\/span><br><span>41<\/span><br><span>42<\/span><br><span>43<\/span><br><span>44<\/span><br><span>45<\/span><br><span>46<\/span><br><span>47<\/span><br><span>48<\/span><br><span>49<\/span><br><span>50<\/span><br><span>51<\/span><br><span>52<\/span><br><span>53<\/span><br><span>54<\/span><br><span>55<\/span><br><span>56<\/span><br><span>57<\/span><br><span>58<\/span><br><span>59<\/span><br><span>60<\/span><br><span>61<\/span><br><span>62<\/span><br><span>63<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>pid &#x3D; &#x2F;usr&#x2F;local&#x2F;var&#x2F;run&#x2F;php-fpm.pid<\/span><br><span>#pid\u8bbe\u7f6e\uff0c\u4e00\u5b9a\u8981\u5f00\u542f,\u4e0a\u9762\u662fMac\u5e73\u53f0\u7684\u3002\u9ed8\u8ba4\u5728php\u5b89\u88c5\u76ee\u5f55\u4e2d\u7684var&#x2F;run&#x2F;php-fpm.pid\u3002\u6bd4\u5982centos\u7684\u5728: &#x2F;usr&#x2F;local&#x2F;php&#x2F;var&#x2F;run&#x2F;php-fpm.pid<\/span><br><span>error_log  &#x3D; &#x2F;usr&#x2F;local&#x2F;var&#x2F;log&#x2F;php-fpm.log<\/span><br><span>#\u9519\u8bef\u65e5\u5fd7\uff0c\u4e0a\u9762\u662fMac\u5e73\u53f0\u7684\uff0c\u9ed8\u8ba4\u5728php\u5b89\u88c5\u76ee\u5f55\u4e2d\u7684var&#x2F;log&#x2F;php-fpm.log\uff0c\u6bd4\u5982centos\u7684\u5728: &#x2F;usr&#x2F;local&#x2F;php&#x2F;var&#x2F;log&#x2F;php-fpm.log<\/span><br><span>log_level &#x3D; notice<\/span><br><span>#\u9519\u8bef\u7ea7\u522b. \u4e0a\u9762\u7684php-fpm.log\u7eaa\u5f55\u7684\u767b\u8bb0\u3002\u53ef\u7528\u7ea7\u522b\u4e3a: alert\uff08\u5fc5\u987b\u7acb\u5373\u5904\u7406\uff09, error\uff08\u9519\u8bef\u60c5\u51b5\uff09, warning\uff08\u8b66\u544a\u60c5\u51b5\uff09, notice\uff08\u4e00\u822c\u91cd\u8981\u4fe1\u606f\uff09, debug\uff08\u8c03\u8bd5\u4fe1\u606f\uff09. \u9ed8\u8ba4: notice.<\/span><br><span>emergency_restart_threshold &#x3D; 60<\/span><br><span>emergency_restart_interval &#x3D; 60s<\/span><br><span>#\u8868\u793a\u5728emergency_restart_interval\u6240\u8bbe\u503c\u5185\u51fa\u73b0SIGSEGV\u6216\u8005SIGBUS\u9519\u8bef\u7684php-cgi\u8fdb\u7a0b\u6570\u5982\u679c\u8d85\u8fc7 emergency_restart_threshold\u4e2a\uff0cphp-fpm\u5c31\u4f1a\u4f18\u96c5\u91cd\u542f\u3002\u8fd9\u4e24\u4e2a\u9009\u9879\u4e00\u822c\u4fdd\u6301\u9ed8\u8ba4\u503c\u30020 \u8868\u793a &#39;\u5173\u95ed\u8be5\u529f\u80fd&#39;. \u9ed8\u8ba4\u503c: 0 (\u5173\u95ed).<\/span><br><span>process_control_timeout &#x3D; 0<\/span><br><span>#\u8bbe\u7f6e\u5b50\u8fdb\u7a0b\u63a5\u53d7\u4e3b\u8fdb\u7a0b\u590d\u7528\u4fe1\u53f7\u7684\u8d85\u65f6\u65f6\u95f4. \u53ef\u7528\u5355\u4f4d: s(\u79d2), m(\u5206), h(\u5c0f\u65f6), \u6216\u8005 d(\u5929) \u9ed8\u8ba4\u5355\u4f4d: s(\u79d2). \u9ed8\u8ba4\u503c: 0.<\/span><br><span>daemonize &#x3D; yes<\/span><br><span>#\u540e\u53f0\u6267\u884cfpm,\u9ed8\u8ba4\u503c\u4e3ayes\uff0c\u5982\u679c\u4e3a\u4e86\u8c03\u8bd5\u53ef\u4ee5\u6539\u4e3ano\u3002\u5728FPM\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u8bbe\u7f6e\u6765\u8fd0\u884c\u591a\u4e2a\u8fdb\u7a0b\u6c60\u3002 \u8fd9\u4e9b\u8bbe\u7f6e\u53ef\u4ee5\u9488\u5bf9\u6bcf\u4e2a\u8fdb\u7a0b\u6c60\u5355\u72ec\u8bbe\u7f6e\u3002<\/span><br><span>listen &#x3D; 127.0.0.1:9000<\/span><br><span>#fpm\u76d1\u542c\u7aef\u53e3\uff0c\u5373nginx\u4e2dphp\u5904\u7406\u7684\u5730\u5740\uff0c\u4e00\u822c\u9ed8\u8ba4\u503c\u5373\u53ef\u3002\u53ef\u7528\u683c\u5f0f\u4e3a: &#39;ip:port&#39;, &#39;port&#39;, &#39;&#x2F;path&#x2F;to&#x2F;unix&#x2F;socket&#39;. \u6bcf\u4e2a\u8fdb\u7a0b\u6c60\u90fd\u9700\u8981\u8bbe\u7f6e\u3002\u5982\u679cnginx\u548cphp\u5728\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u5206\u5e03\u5f0f\u5904\u7406\uff0c\u5c31\u8bbe\u7f6eip\u8fd9\u91cc\u5c31\u53ef\u4ee5\u4e86\u3002<\/span><br><span>listen.backlog &#x3D; -1<\/span><br><span>#backlog\u6570\uff0c\u8bbe\u7f6e listen \u7684\u534a\u8fde\u63a5\u961f\u5217\u957f\u5ea6\uff0c-1\u8868\u793a\u65e0\u9650\u5236\uff0c\u7531\u64cd\u4f5c\u7cfb\u7edf\u51b3\u5b9a\uff0c\u6b64\u884c\u6ce8\u91ca\u6389\u5c31\u884c\u3002backlog\u542b\u4e49\u53c2\u8003\uff1ahttp:&#x2F;&#x2F;www.3gyou.cc&#x2F;?p&#x3D;41<\/span><br><span>listen.allowed_clients &#x3D; 127.0.0.1<\/span><br><span>#\u5141\u8bb8\u8bbf\u95eeFastCGI\u8fdb\u7a0b\u7684IP\u767d\u540d\u5355\uff0c\u8bbe\u7f6eany\u4e3a\u4e0d\u9650\u5236IP\uff0c\u5982\u679c\u8981\u8bbe\u7f6e\u5176\u4ed6\u4e3b\u673a\u7684nginx\u4e5f\u80fd\u8bbf\u95ee\u8fd9\u53f0FPM\u8fdb\u7a0b\uff0clisten\u5904\u8981\u8bbe\u7f6e\u6210\u672c\u5730\u53ef\u88ab\u8bbf\u95ee\u7684IP\u3002\u9ed8\u8ba4\u503c\u662fany\u3002\u6bcf\u4e2a\u5730\u5740\u662f\u7528\u9017\u53f7\u5206\u9694. \u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\u6216\u8005\u4e3a\u7a7a\uff0c\u5219\u5141\u8bb8\u4efb\u4f55\u670d\u52a1\u5668\u8bf7\u6c42\u8fde\u63a5\u3002<\/span><br><span>listen.owner &#x3D; www<\/span><br><span>listen.group &#x3D; www<\/span><br><span>listen.mode &#x3D; 0666<\/span><br><span>#unix socket\u8bbe\u7f6e\u9009\u9879\uff0c\u5982\u679c\u4f7f\u7528tcp\u65b9\u5f0f\u8bbf\u95ee\uff0c\u8fd9\u91cc\u6ce8\u91ca\u5373\u53ef\u3002<\/span><br><span>user &#x3D; www<\/span><br><span>group &#x3D; www<\/span><br><span>#\u542f\u52a8\u8fdb\u7a0b\u7684\u7528\u6237\u548c\u7528\u6237\u7ec4\uff0cFPM \u8fdb\u7a0b\u8fd0\u884c\u7684Unix\u7528\u6237, \u5fc5\u987b\u8981\u8bbe\u7f6e\u3002\u7528\u6237\u7ec4\uff0c\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\uff0c\u5219\u9ed8\u8ba4\u7528\u6237\u7684\u7ec4\u88ab\u4f7f\u7528\u3002<\/span><br><span>pm &#x3D; dynamic <\/span><br><span>#php-fpm\u8fdb\u7a0b\u542f\u52a8\u6a21\u5f0f\uff0cpm\u53ef\u4ee5\u8bbe\u7f6e\u4e3astatic\u548cdynamic\u548condemand<\/span><br><span>#\u5982\u679c\u9009\u62e9static\uff0c\u5219\u8fdb\u7a0b\u6570\u5c31\u6570\u56fa\u5b9a\u7684\uff0c\u7531pm.max_children\u6307\u5b9a\u56fa\u5b9a\u7684\u5b50\u8fdb\u7a0b\u6570\u3002<\/span><br><span>#\u5982\u679c\u9009\u62e9dynamic\uff0c\u5219\u8fdb\u7a0b\u6570\u662f\u52a8\u6001\u53d8\u5316\u7684,\u7531\u4ee5\u4e0b\u53c2\u6570\u51b3\u5b9a\uff1a<\/span><br><span>pm.max_children &#x3D; 50 #\u5b50\u8fdb\u7a0b\u6700\u5927\u6570<\/span><br><span>pm.start_servers &#x3D; 2 #\u542f\u52a8\u65f6\u7684\u8fdb\u7a0b\u6570\uff0c\u9ed8\u8ba4\u503c\u4e3a: min_spare_servers + (max_spare_servers - min_spare_servers) &#x2F; 2<\/span><br><span>pm.min_spare_servers &#x3D; 1 #\u4fdd\u8bc1\u7a7a\u95f2\u8fdb\u7a0b\u6570\u6700\u5c0f\u503c\uff0c\u5982\u679c\u7a7a\u95f2\u8fdb\u7a0b\u5c0f\u4e8e\u6b64\u503c\uff0c\u5219\u521b\u5efa\u65b0\u7684\u5b50\u8fdb\u7a0b<\/span><br><span>pm.max_spare_servers &#x3D; 3 #\uff0c\u4fdd\u8bc1\u7a7a\u95f2\u8fdb\u7a0b\u6570\u6700\u5927\u503c\uff0c\u5982\u679c\u7a7a\u95f2\u8fdb\u7a0b\u5927\u4e8e\u6b64\u503c\uff0c\u6b64\u8fdb\u884c\u6e05\u7406<\/span><br><span>pm.max_requests &#x3D; 500<\/span><br><span>#\u8bbe\u7f6e\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u91cd\u751f\u4e4b\u524d\u670d\u52a1\u7684\u8bf7\u6c42\u6570. \u5bf9\u4e8e\u53ef\u80fd\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f\u7684\u7b2c\u4e09\u65b9\u6a21\u5757\u6765\u8bf4\u662f\u975e\u5e38\u6709\u7528\u7684. \u5982\u679c\u8bbe\u7f6e\u4e3a &#39;0&#39; \u5219\u4e00\u76f4\u63a5\u53d7\u8bf7\u6c42. \u7b49\u540c\u4e8e PHP_FCGI_MAX_REQUESTS \u73af\u5883\u53d8\u91cf. \u9ed8\u8ba4\u503c: 0.<\/span><br><span>pm.status_path &#x3D; &#x2F;status<\/span><br><span>#FPM\u72b6\u6001\u9875\u9762\u7684\u7f51\u5740. \u5982\u679c\u6ca1\u6709\u8bbe\u7f6e, \u5219\u65e0\u6cd5\u8bbf\u95ee\u72b6\u6001\u9875\u9762. \u9ed8\u8ba4\u503c: none. munin\u76d1\u63a7\u4f1a\u4f7f\u7528\u5230<\/span><br><span>ping.path &#x3D; &#x2F;ping<\/span><br><span>#FPM\u76d1\u63a7\u9875\u9762\u7684ping\u7f51\u5740. \u5982\u679c\u6ca1\u6709\u8bbe\u7f6e, \u5219\u65e0\u6cd5\u8bbf\u95eeping\u9875\u9762. \u8be5\u9875\u9762\u7528\u4e8e\u5916\u90e8\u68c0\u6d4bFPM\u662f\u5426\u5b58\u6d3b\u5e76\u4e14\u53ef\u4ee5\u54cd\u5e94\u8bf7\u6c42. \u8bf7\u6ce8\u610f\u5fc5\u987b\u4ee5\u659c\u7ebf\u5f00\u5934 (&#x2F;)\u3002<\/span><br><span>ping.response &#x3D; pong<\/span><br><span>#\u7528\u4e8e\u5b9a\u4e49ping\u8bf7\u6c42\u7684\u8fd4\u56de\u76f8\u5e94. \u8fd4\u56de\u4e3a HTTP 200 \u7684 text&#x2F;plain \u683c\u5f0f\u6587\u672c. \u9ed8\u8ba4\u503c: pong.<\/span><br><span>access.log &#x3D; log&#x2F;$pool.access.log<\/span><br><span>#\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u7684\u8bbf\u95ee\u65e5\u5fd7\uff0c\u9ed8\u8ba4\u662f\u5173\u95ed\u7684\u3002<\/span><br><span>access.format &#x3D; &quot;%R - %u %t &quot;%m %r%Q%q&quot; %s %f %&#123;mili&#125;d %&#123;kilo&#125;M %C%%&quot;<\/span><br><span>#\u8bbe\u5b9a\u8bbf\u95ee\u65e5\u5fd7\u7684\u683c\u5f0f\u3002<\/span><br><span>slowlog &#x3D; log&#x2F;$pool.log.slow<\/span><br><span>#\u6162\u8bf7\u6c42\u7684\u8bb0\u5f55\u65e5\u5fd7,\u914d\u5408request_slowlog_timeout\u4f7f\u7528\uff0c\u9ed8\u8ba4\u5173\u95ed<\/span><br><span>request_slowlog_timeout &#x3D; 10s<\/span><br><span>#\u5f53\u4e00\u4e2a\u8bf7\u6c42\u8be5\u8bbe\u7f6e\u7684\u8d85\u65f6\u65f6\u95f4\u540e\uff0c\u5c31\u4f1a\u5c06\u5bf9\u5e94\u7684PHP\u8c03\u7528\u5806\u6808\u4fe1\u606f\u5b8c\u6574\u5199\u5165\u5230\u6162\u65e5\u5fd7\u4e2d. \u8bbe\u7f6e\u4e3a &#39;0&#39; \u8868\u793a &#39;Off&#39;<\/span><br><span>request_terminate_timeout &#x3D; 0<\/span><br><span>#\u8bbe\u7f6e\u5355\u4e2a\u8bf7\u6c42\u7684\u8d85\u65f6\u4e2d\u6b62\u65f6\u95f4. \u8be5\u9009\u9879\u53ef\u80fd\u4f1a\u5bf9php.ini\u8bbe\u7f6e\u4e2d\u7684&#39;max_execution_time&#39;\u56e0\u4e3a\u67d0\u4e9b\u7279\u6b8a\u539f\u56e0\u6ca1\u6709\u4e2d\u6b62\u8fd0\u884c\u7684\u811a\u672c\u6709\u7528. \u8bbe\u7f6e\u4e3a &#39;0&#39; \u8868\u793a &#39;Off&#39;.\u5f53\u7ecf\u5e38\u51fa\u73b0502\u9519\u8bef\u65f6\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u6539\u6b64\u9009\u9879\u3002<\/span><br><span>rlimit_files &#x3D; 1024<\/span><br><span>#\u8bbe\u7f6e\u6587\u4ef6\u6253\u5f00\u63cf\u8ff0\u7b26\u7684rlimit\u9650\u5236. \u9ed8\u8ba4\u503c: \u7cfb\u7edf\u5b9a\u4e49\u503c\u9ed8\u8ba4\u53ef\u6253\u5f00\u53e5\u67c4\u662f1024\uff0c\u53ef\u4f7f\u7528 ulimit -n\u67e5\u770b\uff0culimit -n 2048\u4fee\u6539\u3002<\/span><br><span>rlimit_core &#x3D; 0<\/span><br><span>#\u8bbe\u7f6e\u6838\u5fc3rlimit\u6700\u5927\u9650\u5236\u503c. \u53ef\u7528\u503c: &#39;unlimited&#39; \u30010\u6216\u8005\u6b63\u6574\u6570. \u9ed8\u8ba4\u503c: \u7cfb\u7edf\u5b9a\u4e49\u503c.<\/span><br><span>chroot &#x3D;<\/span><br><span>#\u542f\u52a8\u65f6\u7684Chroot\u76ee\u5f55. \u6240\u5b9a\u4e49\u7684\u76ee\u5f55\u9700\u8981\u662f\u7edd\u5bf9\u8def\u5f84. \u5982\u679c\u6ca1\u6709\u8bbe\u7f6e, \u5219chroot\u4e0d\u88ab\u4f7f\u7528.<\/span><br><span>chdir &#x3D;<\/span><br><span>#\u8bbe\u7f6e\u542f\u52a8\u76ee\u5f55\uff0c\u542f\u52a8\u65f6\u4f1a\u81ea\u52a8Chdir\u5230\u8be5\u76ee\u5f55. \u6240\u5b9a\u4e49\u7684\u76ee\u5f55\u9700\u8981\u662f\u7edd\u5bf9\u8def\u5f84. \u9ed8\u8ba4\u503c: \u5f53\u524d\u76ee\u5f55\uff0c\u6216\u8005&#x2F;\u76ee\u5f55\uff08chroot\u65f6\uff09<\/span><br><span>catch_workers_output &#x3D; yes<\/span><br><span>#\u91cd\u5b9a\u5411\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684stdout\u548cstderr\u5230\u4e3b\u8981\u7684\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6\u4e2d. \u5982\u679c\u6ca1\u6709\u8bbe\u7f6e, stdout \u548c stderr \u5c06\u4f1a\u6839\u636eFastCGI\u7684\u89c4\u5219\u88ab\u91cd\u5b9a\u5411\u5230 &#x2F;dev&#x2F;null . \u9ed8\u8ba4\u503c: \u7a7a.<\/span><br><span>\u5f53\u7136\u8fd8\u6709\u4e00\u4e9b\u65e0\u5173\u7d27\u8981\u7684\u8bbe\u7f6e\uff0c\u7528\u5230\u4e86\u518d\u8bf4\u5427\u3002<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h2><a href=\"https:\/\/www.studytime.xin\/article\/#\u4e00\u4e9b\u91cd\u8981\u7684\u8bbe\u7f6e\" title=\"\u4e00\u4e9b\u91cd\u8981\u7684\u8bbe\u7f6e\"><\/a>\u4e00\u4e9b\u91cd\u8981\u7684\u8bbe\u7f6e<\/h2>\n<p>php-fpm\u8fdb\u7a0b\u5206\u914d<br \/>\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\u5c31\u8bf4\u8fc7\u4e86\u3002\u5728fasgcgi\u6a21\u5f0f\u4e0b\uff0cphp\u4f1a\u542f\u52a8\u591a\u4e2aphp-fpm\u8fdb\u7a0b\uff0c\u6765\u63a5\u6536nginx\u53d1\u6765\u7684\u8bf7\u6c42\uff0c\u90a3\u662f\u4e0d\u662f\u8fdb\u7a0b\u8d8a\u591a\uff0c\u901f\u5ea6\u5c31\u8d8a\u5feb\u5462\uff1f\u8fd9\u53ef\u4e0d\u4e00\u5b9a\uff01\u5f97\u6839\u636e\u6211\u4eec\u7684\u673a\u5668\u914d\u7f6e\u548c\u4e1a\u52a1\u91cf\u6765\u51b3\u5b9a\u3002<\/p>\n<p>\u6211\u4eec\u5148\u6765\u770b\u4e0b\uff0c\u8bbe\u5b9a\u8fdb\u7a0b\u7684\u914d\u7f6e\u5728\u54ea\u91cc\uff1f<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>pm &#x3D; static | dynamic | ondemand<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p>pm\u53ef\u4ee5\u8bbe\u7f6e\u6210\u8fd9\u68373\u79cd\uff0c\u6211\u4eec\u7528\u7684\u6700\u591a\u7684\u5c31\u4e0a\u524d\u97622\u79cd\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#pm-static-\u6a21\u5f0f\" title=\"pm = static \u6a21\u5f0f\"><\/a>pm = static \u6a21\u5f0f<\/h3>\n<p>pm = static \u8868\u793a\u6211\u4eec\u521b\u5efa\u7684php-fpm\u5b50\u8fdb\u7a0b\u6570\u91cf\u662f\u56fa\u5b9a\u7684\uff0c\u90a3\u4e48\u5c31\u53ea\u6709pm.max_children = 50\u8fd9\u4e2a\u53c2\u6570\u751f\u6548\u3002\u4f60\u542f\u52a8php-fpm\u7684\u65f6\u5019\u5c31\u4f1a\u4e00\u8d77\u5168\u90e8\u542f\u52a851(1\u4e2a\u4e3b\uff0b50\u4e2a\u5b50)\u4e2a\u8fdb\u7a0b\uff0c\u9887\u4e3a\u58ee\u89c2\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#pm-dynamic-\u6a21\u5f0f\" title=\"pm = dynamic \u6a21\u5f0f\"><\/a>pm = dynamic \u6a21\u5f0f<\/h3>\n<p>pm = dynamic\u6a21\u5f0f\uff0c\u8868\u793a\u542f\u52a8\u8fdb\u7a0b\u662f\u52a8\u6001\u5206\u914d\u7684\uff0c\u968f\u7740\u8bf7\u6c42\u91cf\u52a8\u6001\u53d8\u5316\u7684\u3002\u4ed6\u7531 pm.max_children\uff0cpm.start_servers\uff0cpm.min_spare_servers\uff0cpm.max_spare_servers \u8fd9\u51e0\u4e2a\u53c2\u6570\u5171\u540c\u51b3\u5b9a\u3002<\/p>\n<p>\u4e0a\u9762\u5df2\u7ecf\u8bb2\u8fc7\uff0c\u8fd9\u91cc\u518d\u91cd\u7533\u4e00\u4e0b\u5427\uff1a<br \/>pm.max_children \uff1d 50 \u662f\u6700\u5927\u53ef\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u7684\u6570\u91cf\u3002\u5fc5\u987b\u8bbe\u7f6e\u3002\u8fd9\u91cc\u8868\u793a\u6700\u591a\u53ea\u80fd50\u4e2a\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p>pm.start_servers = 20 \u968f\u7740php-fpm\u4e00\u8d77\u542f\u52a8\u65f6\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u6570\u76ee\u3002\u9ed8\u8ba4\u503c\uff1amin_spare_servers + (max_spare_servers &#8211; min_spare_servers) \/ 2\u3002\u8fd9\u91cc\u8868\u793a\uff0c\u4e00\u8d77\u542f\u52a8\u4f1a\u670920\u4e2a\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p>pm.min_spare_servers = 10<br \/>\u8bbe\u7f6e\u670d\u52a1\u5668\u7a7a\u95f2\u65f6\u6700\u5c0fphp-fpm\u8fdb\u7a0b\u6570\u91cf\u3002\u5fc5\u987b\u8bbe\u7f6e\u3002\u5982\u679c\u7a7a\u95f2\u7684\u65f6\u5019\uff0c\u4f1a\u68c0\u67e5\u5982\u679c\u5c11\u4e8e10\u4e2a\uff0c\u5c31\u4f1a\u542f\u52a8\u51e0\u4e2a\u6765\u8865\u4e0a\u3002<\/p>\n<p>pm.max_spare_servers = 30<br \/>\u8bbe\u7f6e\u670d\u52a1\u5668\u7a7a\u95f2\u65f6\u6700\u5927php-fpm\u8fdb\u7a0b\u6570\u91cf\u3002\u5fc5\u987b\u8bbe\u7f6e\u3002\u5982\u679c\u7a7a\u95f2\u65f6\uff0c\u4f1a\u68c0\u67e5\u8fdb\u7a0b\u6570\uff0c\u591a\u4e8e30\u4e2a\u4e86\uff0c\u5c31\u4f1a\u5173\u95ed\u51e0\u4e2a\uff0c\u8fbe\u523030\u4e2a\u7684\u72b6\u6001\u3002<\/p>\n<p>\u5230\u5e95\u9009\u62e9static\u8fd8\u6570dynamic?<br \/>\u5f88\u591a\u4eba\u6050\u60e7\u75c7\u6765\u88ad\uff0c\u4e0d\u77e5\u9053\u9009\u4ec0\u4e48\u597d\uff1f<\/p>\n<p>\u4e00\u822c\u539f\u5219\u662f\uff1a\u52a8\u6001\u9002\u5408\u5c0f\u5185\u5b58\u673a\u5668\uff0c\u7075\u6d3b\u5206\u914d\u8fdb\u7a0b\uff0c\u7701\u5185\u5b58\u3002\u9759\u6001\u9002\u7528\u4e8e\u5927\u5185\u5b58\u673a\u5668\uff0c\u52a8\u6001\u521b\u5efa\u56de\u6536\u8fdb\u7a0b\u5bf9\u670d\u52a1\u5668\u8d44\u6e90\u4e5f\u662f\u4e00\u79cd\u6d88\u8017\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u5185\u5b58\u5f88\u5927\uff0c\u67098-20G\uff0c\u6309\u7167\u4e00\u4e2aphp-fpm\u8fdb\u7a0b20M\u7b97\uff0c100\u4e2a\u5c312G\u5185\u5b58\u4e86\uff0c\u90a3\u5c31\u53ef\u4ee5\u5f00\u542fstatic\u6a21\u5f0f\u3002\u5982\u679c\u4f60\u7684\u5185\u5b58\u5f88\u5c0f\uff0c\u6bd4\u5982\u624d256M\uff0c\u90a3\u5c31\u8981\u5c0f\u5fc3\u8bbe\u7f6e\u4e86\uff0c\u56e0\u4e3a\u4f60\u7684\u673a\u5668\u91cc\u9762\u7684\u5176\u4ed6\u7684\u8fdb\u7a0b\u4e5f\u7b97\u9700\u8981\u5360\u7528\u5185\u5b58\u7684\uff0c\u6240\u4ee5\u8bbe\u7f6e\u6210dynamic\u662f\u6700\u597d\u7684\uff0c\u6bd4\u5982\uff1apm.max_chindren = 8, \u5360\u7528\u5185\u5b58160M\u5de6\u53f3\uff0c\u800c\u4e14\u53ef\u4ee5\u968f\u65f6\u53d8\u5316\uff0c\u5bf9\u4e8e\u4e00\u534a\u8bbf\u95ee\u91cf\u7684\u7f51\u7ad9\u8db3\u591f\u4e86\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u6162\u65e5\u5fd7\u67e5\u8be2\" title=\"\u6162\u65e5\u5fd7\u67e5\u8be2\"><\/a>\u6162\u65e5\u5fd7\u67e5\u8be2<\/h3>\n<p>\u6211\u4eec\u6709\u65f6\u5019\u4f1a\u7ecf\u5e38\u9971\u53d7500,502\u95ee\u9898\u56f0\u6270\u3002\u5f53nginx\u6536\u5230\u5982\u4e0a\u9519\u8bef\u7801\u65f6\uff0c\u53ef\u4ee5\u786e\u5b9a\u540e\u7aefphp-fpm\u89e3\u6790php\u51fa\u4e86\u67d0\u79cd\u95ee\u9898\uff0c\u6bd4\u5982\uff0c\u6267\u884c\u9519\u8bef\uff0c\u6267\u884c\u8d85\u65f6\u3002<\/p>\n<p>\u8fd9\u4e2a\u65f6\u5019\uff0c\u6211\u4eec\u662f\u53ef\u4ee5\u5f00\u542f\u6162\u65e5\u5fd7\u529f\u80fd\u7684\u3002<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>slowlog &#x3D; &#x2F;usr&#x2F;local&#x2F;var&#x2F;log&#x2F;php-fpm.log.slow<\/span><br><span>request_slowlog_timeout &#x3D; 15s<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p>\u5f53\u4e00\u4e2a\u8bf7\u6c42\u8be5\u8bbe\u7f6e\u7684\u8d85\u65f6\u65f6\u95f415\u79d2\u540e\uff0c\u5c31\u4f1a\u5c06\u5bf9\u5e94\u7684PHP\u8c03\u7528\u5806\u6808\u4fe1\u606f\u5b8c\u6574\u5199\u5165\u5230\u6162\u65e5\u5fd7\u4e2d\u3002<\/p>\n<p>php-fpm\u6162\u65e5\u5fd7\u4f1a\u8bb0\u5f55\u4e0b\u8fdb\u7a0b\u53f7\uff0c\u811a\u672c\u540d\u79f0\uff0c\u5177\u4f53\u54ea\u4e2a\u6587\u4ef6\u54ea\u884c\u4ee3\u7801\u7684\u54ea\u4e2a\u51fd\u6570\u6267\u884c\u65f6\u95f4\u8fc7\u957f\uff1a<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>[21-Nov-2013 14:30:38] [pool www] pid 11877<\/span><br><span>script_filename &#x3D; &#x2F;usr&#x2F;local&#x2F;lnmp&#x2F;nginx&#x2F;html&#x2F;www.quancha.cn&#x2F;www&#x2F;fyzb.php<\/span><br><span>[0xb70fb88c] file_get_contents() &#x2F;usr&#x2F;local&#x2F;lnmp&#x2F;nginx&#x2F;html&#x2F;www.quancha.cn&#x2F;www&#x2F;fyzb.php:2<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p>\u901a\u8fc7\u65e5\u5fd7\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u77e5\u9053\u7b2c2\u884c\u7684file_get_contents \u51fd\u6570\u6709\u70b9\u95ee\u9898\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u8ffd\u8e2a\u95ee\u9898\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u5217\u51fa\u914d\u7f6e\u6587\u4ef6php-fpm\u7684\u5404&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/131757"}],"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=131757"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/131757\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131757"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}