{"id":46802,"date":"2025-07-30T04:11:54","date_gmt":"2025-07-29T20:11:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46802.html"},"modified":"2025-07-30T04:11:54","modified_gmt":"2025-07-29T20:11:54","slug":"%e4%ba%a7%e5%93%81sapi%ef%bc%9a%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%8e%a5%e5%8f%a3%e7%bc%96%e7%a8%8b%e4%b8%8ephp%e9%9b%86%e6%88%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46802.html","title":{"rendered":"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210"},"content":{"rendered":"<p>  \u672c\u6587\u8fd8\u6709\u914d\u5957\u7684\u7cbe\u54c1\u8d44\u6e90&#xff0c;\u70b9\u51fb\u83b7\u53d6  <img decoding=\"async\" alt=\"menu-r.4af5f7ec.gif\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201153-68892b095f84c.gif\" style=\"width:16px;margin-left:4px;vertical-align:text-bottom;cursor:text\" \/> <\/p>\n<p> \u7b80\u4ecb&#xff1a;\u201c\u4ea7\u54c1_sapi\u201d\u53ef\u80fd\u6307\u4e00\u4e2a\u4e0eServer Application Programming Interface&#xff08;SAPI&#xff09;\u7ed3\u5408\u7684\u7279\u5b9a\u4ea7\u54c1\u3002SAPI\u662fPHP\u4e2d\u7684\u5173\u952e\u6982\u5ff5&#xff0c;\u5b83\u6807\u51c6\u5316\u4e86PHP\u4e0eWeb\u670d\u52a1\u5668\u7684\u4ea4\u4e92\u65b9\u5f0f\u3002\u672c\u6587\u63a2\u8ba8\u4e86SAPI\u7684\u57fa\u672c\u6982\u5ff5\u3001PHP\u4e0eSAPI\u7684\u5173\u7cfb\u3001SAPI\u7684\u4f5c\u7528\u3001\u5e38\u89c1\u7684SAPI\u793a\u4f8b&#xff0c;\u4ee5\u53ca\u5728\u9009\u62e9SAPI\u65f6\u7684\u8003\u8651\u56e0\u7d20\u3002\u6b64\u5916&#xff0c;\u672c\u6587\u5bf9\u201c\u4ea7\u54c1_sapi\u201d\u7684\u53ef\u80fd\u542b\u4e49\u8fdb\u884c\u4e86\u8ba8\u8bba&#xff0c;\u6307\u51fa\u5b83\u53ef\u80fd\u662f\u4e00\u4e2a\u7279\u5b9a\u4ea7\u54c1\u6216\u670d\u52a1\u7684SAPI\u5b9e\u73b0&#xff0c;\u65e8\u5728\u63d0\u4f9b\u6027\u80fd\u4f18\u5316\u3001\u589e\u5f3a\u5b89\u5168\u6216\u7279\u5b9a\u96c6\u6210\u9700\u6c42\u3002  <img decoding=\"async\" alt=\"\u4ea7\u54c1_sapi\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201153-68892b0967941.jpg\" \/> <\/p>\n<h2> 1. SAPI\u5b9a\u4e49\u4e0e\u4f5c\u7528 <\/h2>\n<h3> 1.1 \u4ec0\u4e48\u662fSAPI <\/h3>\n<p> \u670d\u52a1\u5668API&#xff08;Server Application Programming Interface&#xff0c;\u7b80\u79f0SAPI&#xff09;\u662fPHP\u7684\u4e00\u4e2a\u62bd\u8c61\u5c42&#xff0c;\u5b83\u5b9a\u4e49\u4e86PHP\u5982\u4f55\u4e0eWeb\u670d\u52a1\u5668\u6216\u5176\u4ed6CGI\u5c01\u88c5\u5668\u4ea4\u4e92\u3002SAPI\u4f7f\u5f97PHP\u80fd\u591f\u72ec\u7acb\u4e8e\u4e0d\u540c\u7684\u670d\u52a1\u5668\u73af\u5883\u8fd0\u884c&#xff0c;\u65e0\u8bba\u662f\u547d\u4ee4\u884c\u754c\u9762&#xff08;CLI&#xff09;\u3001Apache\u6a21\u5757\u3001Nginx\u6a21\u5757\u8fd8\u662f\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684CGI\u7a0b\u5e8f\u3002 <\/p>\n<h3> 1.2 SAPI\u7684\u89d2\u8272\u4e0e\u4f5c\u7528 <\/h3>\n<p> SAPI\u7684\u4f5c\u7528\u53ef\u4ee5\u7c7b\u6bd4\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3&#xff08;API&#xff09;&#xff0c;\u5b83\u5141\u8bb8PHP\u811a\u672c\u4e0e\u7279\u5b9a\u7684\u670d\u52a1\u5668\u73af\u5883\u8fdb\u884c\u901a\u4fe1\u3002\u901a\u8fc7SAPI&#xff0c;PHP\u53ef\u4ee5\u4f5c\u4e3a\u52a8\u6001\u7f51\u9875\u7684\u4e00\u90e8\u5206\u6765\u6267\u884c&#xff0c;\u4e5f\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e0b\u72ec\u7acb\u8fd0\u884c\u3002\u8fd9\u4e00\u5c42\u62bd\u8c61\u7684\u91cd\u8981\u6027\u5728\u4e8e\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u5f0f&#xff0c;\u4f7f\u5f97PHP\u4ee3\u7801\u80fd\u591f\u4e0d\u8003\u8651\u5e95\u5c42\u670d\u52a1\u5668\u7684\u5dee\u5f02&#xff0c;\u4ece\u800c\u5728\u4e0d\u540c\u7684\u73af\u5883\u91cc\u4fdd\u6301\u4e00\u81f4\u7684\u529f\u80fd\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002 <\/p>\n<h3> 1.3 SAPI\u4e0eWeb\u5e94\u7528\u7684\u5173\u7cfb <\/h3>\n<p> SAPI\u662fWeb\u5e94\u7528\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u91cd\u8981\u8fde\u63a5\u70b9\u3002\u4f8b\u5982&#xff0c;\u5982\u679cPHP\u811a\u672c\u662f\u901a\u8fc7Apache\u7684mod_php SAPI\u6a21\u5757\u8fd0\u884c\u7684&#xff0c;\u5f53\u6d4f\u89c8\u5668\u8bf7\u6c42\u4e00\u4e2aPHP\u9875\u9762\u65f6&#xff0c;Apache\u4f1a\u8c03\u7528mod_php\u6765\u6267\u884c\u8fd9\u4e2a\u811a\u672c\u3002\u811a\u672c\u6267\u884c\u5b8c\u6bd5\u540e&#xff0c;PHP\u901a\u8fc7SAPI\u5c06\u8f93\u51fa\u53d1\u9001\u56de\u670d\u52a1\u5668&#xff0c;\u670d\u52a1\u5668\u518d\u5c06\u8f93\u51fa\u53d1\u9001\u5230\u7528\u6237\u7684\u6d4f\u89c8\u5668\u3002\u56e0\u6b64&#xff0c;SAPI\u8d1f\u8d23\u7ba1\u7406\u8bf7\u6c42\u3001\u5904\u7406\u8f93\u5165\u548c\u8f93\u51fa&#xff0c;\u5e76\u4e14\u5728\u670d\u52a1\u5668\u548cPHP\u4e4b\u95f4\u7ef4\u62a4\u9002\u5f53\u7684\u4e0a\u4e0b\u6587\u73af\u5883\u3002 <\/p>\n<p> \u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;SAPI\u5141\u8bb8\u5f00\u53d1\u8005\u4e13\u6ce8\u4e8e\u7f16\u5199PHP\u4ee3\u7801&#xff0c;\u800c\u4e0d\u5fc5\u5173\u5fc3\u5e95\u5c42\u7684\u670d\u52a1\u5668\u7ec6\u8282&#xff0c;\u7b80\u5316\u4e86\u5e94\u7528\u7684\u5f00\u53d1\u4e0e\u90e8\u7f72\u8fc7\u7a0b\u3002\u5728\u540e\u7eed\u7ae0\u8282\u4e2d&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8PHP\u4e0eSAPI\u5982\u4f55\u534f\u540c\u5de5\u4f5c&#xff0c;\u4ee5\u53caSAPI\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u7684\u8868\u73b0\u548c\u4f18\u5316\u65b9\u6cd5\u3002 <\/p>\n<h2> 2. PHP\u4e0eSAPI\u7684\u5173\u7cfb <\/h2>\n<h4> 2.1 PHP\u4e0eSAPI\u7684\u534f\u540c\u5de5\u4f5c\u539f\u7406 <\/h4>\n<h5> 2.1.1 SAPI\u5728PHP\u67b6\u6784\u4e2d\u7684\u89d2\u8272 <\/h5>\n<p> SAPI&#xff08;Server Application Programming Interface&#xff09;\u662fPHP\u7528\u4e8e\u4e0eWeb\u670d\u52a1\u5668\u4ea4\u4e92\u7684\u4e00\u5c42\u62bd\u8c61\u3002\u5b83\u5145\u5f53Web\u670d\u52a1\u5668\u4e0ePHP\u811a\u672c\u4e4b\u95f4\u7684\u6865\u6881&#xff0c;\u5141\u8bb8PHP\u5904\u7406\u6765\u81eaHTTP\u8bf7\u6c42\u7684\u6570\u636e&#xff0c;\u5e76\u5c06\u5904\u7406\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002SAPI\u7684\u51fa\u73b0&#xff0c;\u786e\u4fdd\u4e86PHP\u80fd\u591f\u72ec\u7acb\u4e8e\u7279\u5b9a\u7684Web\u670d\u52a1\u5668\u8fd0\u884c&#xff0c;\u4f7f\u5f97PHP\u65e2\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u6a21\u5757\u8fd0\u884c\u5728\u5982Apache\u6216Nginx\u8fd9\u6837\u7684\u670d\u52a1\u5668\u4e0a&#xff0c;\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u72ec\u7acb\u7684\u811a\u672c\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u6267\u884c\u3002 <\/p>\n<p> SAPI\u6a21\u5757\u5728PHP\u67b6\u6784\u4e2d\u626e\u6f14\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272\u3002\u9996\u5148&#xff0c;\u5b83\u8d1f\u8d23\u521d\u59cb\u5316\u548c\u7ba1\u7406PHP\u7684\u6267\u884c\u73af\u5883&#xff0c;\u5305\u62ec\u5185\u5b58\u5206\u914d\u3001\u53d8\u91cf\u521d\u59cb\u5316\u7b49\u3002\u5176\u6b21&#xff0c;\u5b83\u5904\u7406\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u8f6c\u6362&#xff0c;\u4f7f\u5f97PHP\u811a\u672c\u80fd\u591f\u4ee5\u4e00\u79cd\u7edf\u4e00\u7684\u65b9\u5f0f\u8bbf\u95ee\u548c\u64cd\u4f5c\u6570\u636e&#xff0c;\u800c\u65e0\u9700\u5173\u5fc3\u5e95\u5c42\u7684\u7f51\u7edc\u901a\u4fe1\u7ec6\u8282\u3002\u6700\u540e&#xff0c;SAPI\u8fd8\u63d0\u4f9b\u4e86\u6269\u5c55\u63a5\u53e3&#xff0c;\u5141\u8bb8\u5f00\u53d1\u8005\u901a\u8fc7\u7f16\u5199\u6269\u5c55\u6a21\u5757\u7684\u65b9\u5f0f&#xff0c;\u589e\u5f3aPHP\u7684\u529f\u80fd\u3002 <\/p>\n<h5> 2.1.2 SAPI\u4e0ePHP\u5185\u6838\u7684\u4ea4\u4e92\u673a\u5236 <\/h5>\n<p> PHP\u5185\u6838\u662fPHP\u811a\u672c\u7684\u6267\u884c\u5f15\u64ce&#xff0c;\u8d1f\u8d23\u89e3\u6790\u3001\u7f16\u8bd1\u548c\u6267\u884cPHP\u4ee3\u7801\u3002\u800cSAPI\u6a21\u5757\u4f5c\u4e3a\u5185\u6838\u4e0e\u5916\u754c\u73af\u5883\u7684\u63a5\u53e3&#xff0c;\u9700\u8981\u4e0e\u5185\u6838\u8fdb\u884c\u7d27\u5bc6\u7684\u4ea4\u4e92\u3002\u5177\u4f53\u800c\u8a00&#xff0c;\u5f53\u4e00\u4e2aHTTP\u8bf7\u6c42\u5230\u8fbeWeb\u670d\u52a1\u5668\u5e76\u88abSAPI\u6a21\u5757\u63a5\u6536\u65f6&#xff0c;SAPI\u6a21\u5757\u4f1a\u8d1f\u8d23\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4&#xff1a; <\/p>\n<li>  \u521d\u59cb\u5316\u8bf7\u6c42\u73af\u5883  &#xff1a;\u5728\u5f00\u59cb\u5904\u7406PHP\u811a\u672c\u4e4b\u524d&#xff0c;SAPI\u6a21\u5757\u9700\u8981\u8bbe\u7f6e\u597d\u73af\u5883\u53d8\u91cf&#xff0c;\u4ee5\u4fbfPHP\u5185\u6838\u80fd\u591f\u83b7\u53d6\u5230\u5fc5\u8981\u7684\u8bf7\u6c42\u4fe1\u606f&#xff0c;\u5982\u8bf7\u6c42\u65b9\u6cd5\u3001\u8bf7\u6c42\u53c2\u6570\u7b49\u3002 <\/li>\n<li>  \u542f\u52a8PHP\u5185\u6838  &#xff1a;SAPI\u6a21\u5757\u901a\u8fc7\u8c03\u7528PHP\u5185\u6838\u7684\u76f8\u5173\u63a5\u53e3\u6765\u542f\u52a8PHP\u811a\u672c\u7684\u6267\u884c&#xff0c;\u8fd9\u5305\u62ec\u8c03\u7528PHP\u89e3\u91ca\u5668\u89e3\u6790PHP\u4ee3\u7801&#xff0c;\u5e76\u8fdb\u884c\u7f16\u8bd1\u548c\u6267\u884c\u3002 <\/li>\n<li>  \u54cd\u5e94\u5904\u7406  &#xff1a;PHP\u811a\u672c\u6267\u884c\u5b8c\u6bd5\u540e&#xff0c;SAPI\u6a21\u5757\u8d1f\u8d23\u6536\u96c6\u811a\u672c\u7684\u8f93\u51fa&#xff0c;\u901a\u5e38\u662f\u4e00\u4e2aHTTP\u54cd\u5e94\u4f53&#xff0c;\u5e76\u5c06\u8be5\u54cd\u5e94\u8fd4\u56de\u7ed9Web\u670d\u52a1\u5668\u3002 <\/li>\n<li>  \u8d44\u6e90\u6e05\u7406  &#xff1a;\u8bf7\u6c42\u5904\u7406\u5b8c\u6210\u540e&#xff0c;SAPI\u6a21\u5757\u8fd8\u8d1f\u8d23\u6e05\u7406\u8bf7\u6c42\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u5404\u79cd\u8d44\u6e90&#xff0c;\u786e\u4fdd\u4e0d\u4f1a\u53d1\u751f\u5185\u5b58\u6cc4\u6f0f\u6216\u5176\u4ed6\u8d44\u6e90\u7ba1\u7406\u95ee\u9898\u3002 <\/li>\n<h4> 2.2 PHP\u811a\u672c\u7684\u8bf7\u6c42\u5904\u7406\u6d41\u7a0b <\/h4>\n<h5> 2.2.1 \u8bf7\u6c42\u7684\u63a5\u6536\u4e0e\u5904\u7406 <\/h5>\n<p> \u5f53PHP\u811a\u672c\u63a5\u6536\u5230\u4e00\u4e2a\u8bf7\u6c42\u65f6&#xff0c;SAPI\u6a21\u5757\u9996\u5148\u9700\u8981\u51b3\u5b9a\u5982\u4f55\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42\u3002\u4ee5mod_php\u4e3a\u4f8b&#xff0c;\u8fd9\u662f\u4e00\u79cd\u76f4\u63a5\u96c6\u6210\u5230Apache Web\u670d\u52a1\u5668\u7684SAPI\u6a21\u5757&#xff0c;\u8bf7\u6c42\u5904\u7406\u6d41\u7a0b\u5927\u81f4\u5982\u4e0b&#xff1a; <\/p>\n<li>  \u8bf7\u6c42\u5230\u8fbeWeb\u670d\u52a1\u5668  &#xff1a;\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u5230Web\u670d\u52a1\u5668\u3002 <\/li>\n<li>  Web\u670d\u52a1\u5668\u4f20\u9012\u8bf7\u6c42\u7ed9SAPI  &#xff1a;Apache\u8bc6\u522b\u5230\u8bf7\u6c42\u662f\u9488\u5bf9PHP\u6587\u4ef6\u7684&#xff0c;\u5e76\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9mod_php SAPI\u6a21\u5757\u3002 <\/li>\n<li>  SAPI\u63a5\u6536\u8bf7\u6c42\u5e76\u521d\u59cb\u5316\u73af\u5883  &#xff1a;mod_php\u4f5c\u4e3aSAPI\u6a21\u5757&#xff0c;\u9996\u5148\u4f1a\u521d\u59cb\u5316\u8bf7\u6c42\u73af\u5883&#xff0c;\u5e76\u51c6\u5907\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\u548c\u4f1a\u8bdd\u4fe1\u606f\u3002 <\/li>\n<li>  PHP\u5185\u6838\u5f00\u59cb\u6267\u884c  &#xff1a;SAPI\u8c03\u7528PHP\u5185\u6838\u5f00\u59cb\u6267\u884c\u811a\u672c&#xff0c;\u5e76\u6839\u636e\u811a\u672c\u6267\u884c\u7ed3\u679c\u51c6\u5907\u54cd\u5e94\u6570\u636e\u3002 <\/li>\n<h5> 2.2.2 \u54cd\u5e94\u7684\u751f\u6210\u4e0e\u53d1\u9001 <\/h5>\n<p> PHP\u811a\u672c\u6267\u884c\u5b8c\u6bd5\u540e&#xff0c;\u5176\u8f93\u51fa\u9700\u8981\u88ab\u8f6c\u6362\u6210HTTP\u54cd\u5e94\u683c\u5f0f&#xff0c;\u5e76\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u4ee5\u4e0b\u662f\u8fd9\u4e00\u8fc7\u7a0b\u7684\u8be6\u7ec6\u6b65\u9aa4&#xff1a; <\/p>\n<li>  \u811a\u672c\u8f93\u51fa\u83b7\u53d6  &#xff1a;PHP\u811a\u672c\u6267\u884c\u5b8c\u6210\u540e&#xff0c;SAPI\u6a21\u5757\u83b7\u53d6\u811a\u672c\u7684\u8f93\u51fa\u5185\u5bb9\u3002 <\/li>\n<li>  HTTP\u5934\u90e8\u51c6\u5907  &#xff1a;\u6839\u636e\u811a\u672c\u7684\u6267\u884c\u60c5\u51b5&#xff08;\u5982\u662f\u5426\u6709\u9519\u8bef\u53d1\u751f&#xff09;&#xff0c;SAPI\u6a21\u5757\u4f1a\u51c6\u5907\u76f8\u5e94\u7684HTTP\u5934\u90e8\u4fe1\u606f\u3002 <\/li>\n<li>  \u53d1\u9001\u54cd\u5e94  &#xff1a;SAPI\u6a21\u5757\u5c06HTTP\u5934\u90e8\u548c\u811a\u672c\u8f93\u51fa\u7ec4\u5408\u6210\u5b8c\u6574\u7684HTTP\u54cd\u5e94&#xff0c;\u5e76\u53d1\u9001\u7ed9Web\u670d\u52a1\u5668&#xff0c;Web\u670d\u52a1\u5668\u518d\u5c06\u54cd\u5e94\u4f20\u9001\u5230\u5ba2\u6237\u7aef\u3002 <\/li>\n<li>  \u8d44\u6e90\u6e05\u7406  &#xff1a;\u5b8c\u6210\u54cd\u5e94\u7684\u53d1\u9001\u540e&#xff0c;SAPI\u6a21\u5757\u8fd8\u4f1a\u8fdb\u884c\u5fc5\u8981\u7684\u8d44\u6e90\u6e05\u7406\u5de5\u4f5c&#xff0c;\u786e\u4fdd\u4e0b\u4e00\u6b21\u8bf7\u6c42\u7684\u5904\u7406\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\u3002 <\/li>\n<h4> 2.3 SAPI\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406 <\/h4>\n<h5> 2.3.1 \u521d\u59cb\u5316\u8fc7\u7a0b\u4e2d\u7684\u5173\u952e\u6b65\u9aa4 <\/h5>\n<p> SAPI\u7684\u521d\u59cb\u5316\u6d89\u53ca\u5230\u4e00\u7cfb\u5217\u590d\u6742\u7684\u6b65\u9aa4&#xff0c;\u4ee5\u4e0b\u662f\u521d\u59cb\u5316\u8fc7\u7a0b\u4e2d\u6700\u4e3a\u5173\u952e\u7684\u51e0\u4e2a\u6b65\u9aa4&#xff1a; <\/p>\n<li>  \u6a21\u5757\u6ce8\u518c  &#xff1a;SAPI\u6a21\u5757\u9700\u8981\u5728PHP\u5185\u6838\u4e2d\u6ce8\u518c\u81ea\u5df1&#xff0c;\u8fd9\u5305\u62ec\u6ce8\u518c\u8bf7\u6c42\u521d\u59cb\u5316\u548c\u7ed3\u675f\u65f6\u7684\u56de\u8c03\u51fd\u6570\u7b49\u3002 <\/li>\n<li>  \u73af\u5883\u53d8\u91cf\u8bbe\u7f6e  &#xff1a;SAPI\u8d1f\u8d23\u8bbe\u7f6ePHP\u5185\u6838\u8fd0\u884c\u6240\u9700\u7684\u73af\u5883\u53d8\u91cf&#xff0c;\u8fd9\u5305\u62ec  $_SERVER  \u6570\u7ec4\u7b49\u3002 <\/li>\n<li>  \u5185\u5b58\u4e0e\u53d8\u91cf\u521d\u59cb\u5316  &#xff1a;\u5728\u5f00\u59cb\u5904\u7406\u8bf7\u6c42\u4e4b\u524d&#xff0c;SAPI\u9700\u8981\u521d\u59cb\u5316\u5185\u5b58\u8d44\u6e90&#xff0c;\u4ee5\u53caPHP\u7684\u5168\u5c40\u53d8\u91cf\u3001\u6570\u7ec4\u548c\u51fd\u6570\u7b49\u3002 <\/li>\n<li>  \u8bf7\u6c42\u5904\u7406\u51fd\u6570\u6ce8\u518c  &#xff1a;SAPI\u6a21\u5757\u8fd8\u9700\u8981\u5c06\u8bf7\u6c42\u5904\u7406\u7684\u56de\u8c03\u51fd\u6570\u6ce8\u518c\u5230PHP\u5185\u6838&#xff0c;\u4ee5\u4fbf\u5185\u6838\u77e5\u9053\u5982\u4f55\u8c03\u7528SAPI\u6765\u5904\u7406\u8bf7\u6c42\u3002 <\/li>\n<h5> 2.3.2 \u8bf7\u6c42\u5468\u671f\u5185\u7684\u8d44\u6e90\u7ba1\u7406 <\/h5>\n<p> \u5728\u8bf7\u6c42\u5468\u671f\u5185&#xff0c;SAPI\u6a21\u5757\u9700\u8981\u5bf9\u8d44\u6e90\u8fdb\u884c\u6709\u6548\u7684\u7ba1\u7406&#xff0c;\u4ee5\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u548c\u5176\u4ed6\u8d44\u6e90\u51b2\u7a81\u3002\u8d44\u6e90\u7ba1\u7406\u7684\u5173\u952e\u70b9\u5305\u62ec&#xff1a; <\/p>\n<li>  \u8bf7\u6c42\u8d44\u6e90\u5206\u914d  &#xff1a;SAPI\u9700\u8981\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u5206\u914d\u72ec\u7acb\u7684\u8d44\u6e90&#xff0c;\u5305\u62ec\u53d8\u91cf\u7a7a\u95f4\u3001\u5185\u5b58\u7b49&#xff0c;\u4ee5\u786e\u4fdd\u8bf7\u6c42\u4e4b\u95f4\u7684\u9694\u79bb\u3002 <\/li>\n<li>  \u8bf7\u6c42\u6267\u884c\u73af\u5883\u7684\u7ef4\u62a4  &#xff1a;\u5728\u8bf7\u6c42\u6267\u884c\u671f\u95f4&#xff0c;SAPI\u6a21\u5757\u9700\u8981\u786e\u4fdd\u6240\u6709\u7684\u8fd0\u884c\u65f6\u6570\u636e\u5f97\u5230\u6b63\u786e\u7ef4\u62a4&#xff0c;\u5982\u4f1a\u8bdd\u4fe1\u606f\u3001\u7528\u6237\u8ba4\u8bc1\u72b6\u6001\u7b49\u3002 <\/li>\n<li>  \u8d44\u6e90\u6e05\u7406\u548c\u56de\u6536  &#xff1a;\u8bf7\u6c42\u5904\u7406\u5b8c\u6bd5\u540e&#xff0c;SAPI\u8d1f\u8d23\u6e05\u7406\u5e76\u56de\u6536\u6240\u6709\u5206\u914d\u7684\u8d44\u6e90&#xff0c;\u8fd9\u4e00\u6b65\u9aa4\u5bf9\u4e8e\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f\u81f3\u5173\u91cd\u8981\u3002 <\/li>\n<li>  \u9519\u8bef\u5904\u7406\u4e0e\u65e5\u5fd7\u8bb0\u5f55  &#xff1a;\u5728\u5904\u7406\u8bf7\u6c42\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u4efb\u4f55\u9519\u8bef&#xff0c;SAPI\u6a21\u5757\u90fd\u5e94\u8be5\u8fdb\u884c\u9002\u5f53\u7684\u9519\u8bef\u5904\u7406&#xff0c;\u5e76\u8bb0\u5f55\u5fc5\u8981\u7684\u65e5\u5fd7\u4fe1\u606f\u4ee5\u4fbf\u95ee\u9898\u8ffd\u8e2a\u3002 <\/li>\n<p>\/\/ \u793a\u4f8b\u4ee3\u7801&#xff1a;PHP\u811a\u672c\u8bf7\u6c42\u5904\u7406\u903b\u8f91\u7684\u7b80\u5316\u4f2a\u4ee3\u7801<\/p>\n<p>\/\/ SAPI\u6a21\u5757\u63a5\u6536\u5230\u8bf7\u6c42<br \/>\nrequest_received();<\/p>\n<p>\/\/ SAPI\u6a21\u5757\u521d\u59cb\u5316\u8bf7\u6c42\u73af\u5883<br \/>\ninitialize_request_environment();<\/p>\n<p>\/\/ \u8c03\u7528PHP\u5185\u6838\u5904\u7406PHP\u811a\u672c<br \/>\n$script_output &#061; php_kernel_execute_script();<\/p>\n<p>\/\/ SAPI\u6a21\u5757\u83b7\u53d6\u8f93\u51fa\u5e76\u751f\u6210HTTP\u54cd\u5e94<br \/>\n$response &#061; generate_http_response($script_output);<\/p>\n<p>\/\/ \u53d1\u9001\u54cd\u5e94\u7ed9\u5ba2\u6237\u7aef<br \/>\nsend_response_to_client($response);<\/p>\n<p>\/\/ \u6e05\u7406\u8d44\u6e90<br \/>\ncleanup_resources();<\/p>\n<p>\/\/ \u9519\u8bef\u5904\u7406\u4e0e\u65e5\u5fd7\u8bb0\u5f55<br \/>\nhandle_errors();<br \/>\nlog_request_details();<\/p>\n<p> \u901a\u8fc7\u4e0a\u8ff0\u7684\u7ae0\u8282\u5185\u5bb9&#xff0c;\u6211\u4eec\u80fd\u591f\u8be6\u7ec6\u4e86\u89e3PHP\u4e0eSAPI\u534f\u540c\u5de5\u4f5c\u539f\u7406&#xff0c;\u4eceSAPI\u5728PHP\u67b6\u6784\u4e2d\u7684\u89d2\u8272\u3001\u8bf7\u6c42\u5904\u7406\u6d41\u7a0b&#xff0c;\u5230SAPI\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406&#xff0c;\u4e86\u89e3\u4e86SAPI\u4e0d\u4ec5\u662fPHP\u4e0eWeb\u670d\u52a1\u5668\u4ea4\u4e92\u7684\u6865\u6881&#xff0c;\u8fd8\u8d1f\u8d23\u7ba1\u7406\u8bf7\u6c42\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u3002 <\/p>\n<h2> 3. SAPI\u7684\u517c\u5bb9\u6027\u3001\u6027\u80fd\u548c\u5b89\u5168\u6027 <\/h2>\n<h3> 3.1 SAPI\u7684\u517c\u5bb9\u6027\u8003\u91cf <\/h3>\n<h4> 3.1.1 \u4e0d\u540c\u7248\u672cPHP\u7684SAPI\u517c\u5bb9\u6027 <\/h4>\n<p> PHP&#xff08;Hypertext Preprocessor&#xff09;\u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5f00\u6e90\u811a\u672c\u8bed\u8a00&#xff0c;\u5176\u7248\u672c\u66f4\u65b0\u5e26\u6765\u4e86\u8bb8\u591a\u65b0\u7279\u6027\u4e0e\u6539\u8fdb\u3002\u4e3a\u4e86\u4fdd\u6301\u4e0e\u65e7\u7248SAPI&#xff08;Server Application Programming Interface&#xff09;\u7684\u5411\u540e\u517c\u5bb9\u6027&#xff0c;PHP\u5f00\u53d1\u56e2\u961f\u91c7\u53d6\u4e86\u591a\u79cd\u63aa\u65bd&#xff0c;\u786e\u4fdd\u65b0\u7684PHP\u7248\u672c\u80fd\u591f\u4e0e\u65e7\u7248SAPI\u65e0\u7f1d\u914d\u5408\u3002 <\/p>\n<p> PHP\u7684SAPI\u901a\u5e38\u4f5c\u4e3aPHP\u6267\u884c\u73af\u5883\u7684\u4e00\u90e8\u5206&#xff0c;\u8d1f\u8d23\u5904\u7406PHP\u89e3\u91ca\u5668\u4e0eWeb\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u4ea4\u4e92\u3002\u4e0d\u540c\u7248\u672c\u7684PHP\u5728SAPI\u517c\u5bb9\u6027\u4e0a&#xff0c;\u4e3b\u8981\u5173\u6ce8\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762&#xff1a; <\/p>\n<ul>\n<li>\n<p>  \u8bed\u6cd5\u4e0e\u7279\u6027\u517c\u5bb9\u6027  &#xff1a;\u65b0\u7248\u672c\u7684PHP\u5f80\u5f80\u5728\u8bed\u6cd5\u4e0a\u517c\u5bb9\u65e7\u7248\u672c&#xff0c;\u4f46\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u6240\u6709\u7684\u65b0\u7279\u6027\u90fd\u80fd\u5728\u65e7\u7248SAPI\u4e0a\u8fd0\u884c\u3002\u65b0\u7248\u672c\u5f15\u5165\u7684\u65b0\u51fd\u6570\u3001\u65b0\u7c7b\u548c\u65b0\u7279\u6027&#xff08;\u5982\u7c7b\u578b\u8054\u5408\u3001\u7a7a\u5408\u5e76\u8fd0\u7b97\u7b26\u7b49&#xff09;\u5728\u65e7\u7248SAPI\u4e0a\u53ef\u80fd\u65e0\u6cd5\u4f7f\u7528&#xff0c;\u9664\u975e\u8fdb\u884c\u4e86\u7279\u5b9a\u7684\u6269\u5c55\u6216\u517c\u5bb9\u6027\u8c03\u6574\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u6269\u5c55\u517c\u5bb9\u6027  &#xff1a;PHP\u7684\u6269\u5c55\u6a21\u5757&#xff08;\u5982PDO\u3001MySQLi\u7b49&#xff09;\u53ef\u80fd\u9700\u8981\u66f4\u65b0\u624d\u80fd\u5728\u65b0\u7248\u672c\u7684PHP\u4e0a\u6b63\u5e38\u5de5\u4f5c\u3002\u5f00\u53d1\u8005\u9700\u8981\u786e\u4fdd\u4ed6\u4eec\u4f7f\u7528\u7684\u6269\u5c55\u5df2\u7ecf\u9002\u914d\u4e86\u65b0PHP\u7248\u672c\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u670d\u52a1\u5668\u517c\u5bb9\u6027  &#xff1a;\u968f\u7740PHP\u7248\u672c\u7684\u5347\u7ea7&#xff0c;\u67d0\u4e9b\u670d\u52a1\u5668\u4e0a\u53ef\u80fd\u5b58\u5728\u7684SAPI\u4e5f\u9700\u66f4\u65b0\u4ee5\u786e\u4fdd\u517c\u5bb9\u3002\u4f8b\u5982&#xff0c;Apache\u670d\u52a1\u5668\u9700\u8981\u66f4\u65b0mod_php\u6a21\u5757&#xff0c;\u4ee5\u4fbf\u4e0e\u65b0PHP\u7248\u672c\u517c\u5bb9\u3002 <\/p>\n<\/li>\n<\/ul>\n<h4> 3.1.2 \u5e38\u89c1\u73af\u5883\u4e0b\u7684SAPI\u914d\u7f6e <\/h4>\n<p> \u5728\u4e0d\u540c\u7684\u670d\u52a1\u5668\u73af\u5883\u4e2d&#xff0c;PHP\u7684SAPI\u6a21\u5757\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7684\u914d\u7f6e\u7b56\u7565&#xff0c;\u4ee5\u4fbf\u4e8e\u9002\u5e94\u4e0d\u540c\u7684\u670d\u52a1\u5668\u8f6f\u4ef6\u548c\u5e94\u7528\u573a\u666f\u3002 <\/p>\n<ul>\n<li>  Apache\u73af\u5883  &#xff1a;\u901a\u5e38\u4f7f\u7528  mod_php  \u4f5c\u4e3aSAPI\u3002\u9700\u8981\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u6a21\u5757\u52a0\u8f7d\u548cPHP\u914d\u7f6e\u8bbe\u7f6e&#xff0c;\u4f8b\u5982&#xff1a; <\/li>\n<\/ul>\n<p>  apache LoadModule php7_module modules\/libphp7.so AddType application\/x-httpd-php .php  <\/p>\n<p> \u5176\u4e2d  php7_module  \u548c  libphp7.so  \u5e94\u66ff\u6362\u4e3a\u5bf9\u5e94PHP\u7248\u672c\u7684\u6a21\u5757\u540d\u79f0\u3002 <\/p>\n<ul>\n<li>  Nginx\u73af\u5883  &#xff1a;Nginx\u539f\u751f\u4e0d\u652f\u6301PHP&#xff0c;\u9700\u8981\u501f\u52a9\u5916\u90e8\u5904\u7406\u7a0b\u5e8f\u5982  php-fpm  \u6216  php-cgi  \u3002\u914d\u7f6e\u793a\u4f8b\u5982\u4e0b&#xff1a; <\/li>\n<\/ul>\n<p>  nginx location ~ \\\\.php$ { fastcgi_pass unix:\/var\/run\/php\/php7.4-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }  <\/p>\n<p> \u5176\u4e2d  php7.4-fpm.sock  \u548c  $document_root  \u5e94\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u8c03\u6574\u3002 <\/p>\n<ul>\n<li>  CLI\u73af\u5883  &#xff1a;\u547d\u4ee4\u884c\u754c\u9762\u4e0b\u7684PHP\u914d\u7f6e\u901a\u5e38\u6bd4\u8f83\u7b80\u5355&#xff0c;\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u6216\u914d\u7f6e\u6587\u4ef6  php.ini  \u8fdb\u884c\u8bbe\u7f6e\u3002 <\/li>\n<\/ul>\n<h3> 3.2 SAPI\u6027\u80fd\u4f18\u5316\u7b56\u7565 <\/h3>\n<h4> 3.2.1 \u6027\u80fd\u76d1\u63a7\u5de5\u5177\u4e0e\u65b9\u6cd5 <\/h4>\n<p> \u4e3a\u4e86\u63d0\u9ad8SAPI\u7684\u6027\u80fd&#xff0c;\u9996\u5148\u9700\u8981\u5bf9\u5f53\u524d\u7cfb\u7edf\u7684\u8fd0\u884c\u72b6\u51b5\u8fdb\u884c\u5168\u9762\u7684\u76d1\u63a7\u548c\u5206\u6790\u3002\u6027\u80fd\u76d1\u63a7\u5de5\u5177\u548c\u65b9\u6cd5\u5e2e\u52a9\u5f00\u53d1\u8005\u4e86\u89e3\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u6027\u80fd\u74f6\u9888&#xff0c;\u4e3a\u8fdb\u4e00\u6b65\u7684\u4f18\u5316\u63d0\u4f9b\u4f9d\u636e\u3002 <\/p>\n<p> \u5e38\u89c1\u7684\u6027\u80fd\u76d1\u63a7\u5de5\u5177\u6709&#xff1a; <\/p>\n<ul>\n<li>  ApacheBench (ab)  &#xff1a;\u7528\u4e8e\u6d4b\u8bd5Web\u670d\u52a1\u5668\u8d1f\u8f7d\u6027\u80fd&#xff0c;\u53ef\u4ee5\u6a21\u62df\u591a\u7528\u6237\u540c\u65f6\u8bbf\u95ee\u3002 <\/li>\n<li>\n<p>  Xdebug  &#xff1a;PHP\u7684\u8c03\u8bd5\u5de5\u5177&#xff0c;\u53ef\u4ee5\u8fdb\u884c\u6027\u80fd\u5206\u6790&#xff0c;\u8bb0\u5f55\u51fd\u6570\u8c03\u7528\u65f6\u95f4\u548c\u5185\u5b58\u6d88\u8017\u3002 <\/p>\n<\/li>\n<li>\n<p>  New Relic\u3001Blackfire  &#xff1a;\u8fd9\u4e9b\u5546\u4e1a\u89e3\u51b3\u65b9\u6848\u63d0\u4f9b\u5b9e\u65f6\u76d1\u63a7\u548c\u6df1\u5165\u6027\u80fd\u5206\u6790&#xff0c;\u80fd\u591f\u6355\u6349\u5230\u5e94\u7528\u7684\u6162\u67e5\u8be2\u3001CPU\u4f7f\u7528\u60c5\u51b5\u548c\u5185\u5b58\u6cc4\u6f0f\u7b49\u5173\u952e\u6027\u80fd\u6307\u6807\u3002 <\/p>\n<\/li>\n<\/ul>\n<p> \u6027\u80fd\u76d1\u63a7\u7684\u65b9\u6cd5\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>\n<p>  \u5b9a\u65f6\u76d1\u63a7  &#xff1a;\u901a\u8fc7\u5b9a\u65f6\u6267\u884c\u6027\u80fd\u6d4b\u8bd5&#xff0c;\u8bb0\u5f55\u5173\u952e\u6027\u80fd\u6307\u6807&#xff0c;\u6bd4\u5982\u54cd\u5e94\u65f6\u95f4\u548c\u541e\u5410\u91cf&#xff0c;\u4ee5\u76d1\u63a7\u6027\u80fd\u53d8\u5316\u8d8b\u52bf\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u4ee3\u7801\u5256\u6790&#xff08;Profiling&#xff09;  &#xff1a;\u5229\u7528Xdebug\u7b49\u5de5\u5177\u5bf9\u4ee3\u7801\u8fdb\u884c\u5256\u6790&#xff0c;\u4e86\u89e3\u54ea\u4e9b\u51fd\u6570\u6216\u65b9\u6cd5\u6d88\u8017\u7684\u65f6\u95f4\u6700\u591a\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u6162\u67e5\u8be2\u65e5\u5fd7\u5206\u6790  &#xff1a;\u9488\u5bf9\u6570\u636e\u5e93\u7684\u6162\u67e5\u8be2\u8fdb\u884c\u65e5\u5fd7\u8bb0\u5f55\u548c\u5206\u6790&#xff0c;\u53ef\u4ee5\u4f7f\u7528MySQL\u7684  slow_query_log  \u53c2\u6570\u8fdb\u884c\u8bbe\u7f6e\u3002 <\/p>\n<\/li>\n<\/ul>\n<h4> 3.2.2 \u6027\u80fd\u8c03\u4f18\u6848\u4f8b\u5206\u6790 <\/h4>\n<p> \u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u6027\u80fd\u8c03\u4f18\u6848\u4f8b\u53ef\u4ee5\u4e3aSAPI\u6027\u80fd\u4f18\u5316\u63d0\u4f9b\u5177\u4f53\u7684\u64cd\u4f5c\u6307\u5f15\u3002\u4e0b\u9762\u5c55\u793a\u4e00\u4e2a\u4f7f\u7528  php-fpm  \u7684\u6027\u80fd\u8c03\u4f18\u6848\u4f8b\u5206\u6790\u3002 <\/p>\n<h5> \u4f18\u5316\u914d\u7f6e <\/h5>\n<p> \u5728  php-fpm  \u4e2d&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574  php.ini  \u914d\u7f6e\u548c  php-fpm.conf  \u6765\u4f18\u5316\u6027\u80fd&#xff1a; <\/p>\n<p>pm.max_children &#061; 50<br \/>\npm.start_servers &#061; 10<br \/>\npm.min_spare_servers &#061; 5<br \/>\npm.max_spare_servers &#061; 15<br \/>\npm.max_requests &#061; 500<\/p>\n<p> \u8fd9\u4e9b\u53c2\u6570\u610f\u5473\u7740  php-fpm  \u5c06\u542f\u52a8\u6700\u591a50\u4e2a\u5b50\u8fdb\u7a0b&#xff0c;\u8d77\u59cb\u65f6\u8fd0\u884c10\u4e2a\u5b50\u8fdb\u7a0b&#xff0c;\u6700\u4f4e\u548c\u6700\u9ad8\u5907\u7528\u5b50\u8fdb\u7a0b\u5206\u522b\u8bbe\u7f6e\u4e3a5\u548c15\u4e2a&#xff0c;\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u5904\u7406\u8bf7\u6c42\u7684\u6700\u5927\u6570\u76ee\u4e3a500\u3002 <\/p>\n<h5> \u4ee3\u7801\u4f18\u5316 <\/h5>\n<p> \u5728PHP\u4ee3\u7801\u5c42\u9762&#xff0c;\u4e5f\u6709\u4e00\u7cfb\u5217\u7684\u4f18\u5316\u7b56\u7565&#xff1a; <\/p>\n<ul>\n<li>\n<p>  \u7f13\u5b58\u673a\u5236  &#xff1a;\u5229\u7528APC\u6216Redis\u7b49\u7f13\u5b58\u7cfb\u7edf\u7f13\u5b58\u5e38\u7528\u6570\u636e&#xff0c;\u51cf\u5c11\u6570\u636e\u5e93\u8bbf\u95ee\u6b21\u6570\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u6570\u636e\u5904\u7406\u4f18\u5316  &#xff1a;\u4f7f\u7528\u66f4\u9ad8\u6548\u7684\u7b97\u6cd5\u5904\u7406\u6570\u636e&#xff0c;\u6bd4\u5982\u5728\u6570\u7ec4\u64cd\u4f5c\u4e2d\u5c3d\u91cf\u51cf\u5c11\u5faa\u73af\u5d4c\u5957\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u6587\u4ef6\u64cd\u4f5c  &#xff1a;\u51cf\u5c11\u6587\u4ef6\u64cd\u4f5c\u6b21\u6570&#xff0c;\u4f7f\u7528\u6587\u4ef6\u9501\u907f\u514d\u5e76\u53d1\u8bfb\u5199\u51b2\u7a81\u3002 <\/p>\n<\/li>\n<\/ul>\n<h5> \u8d44\u6e90\u9650\u5236 <\/h5>\n<p> \u8d44\u6e90\u9650\u5236\u4e5f\u662f\u91cd\u8981\u7684\u4f18\u5316\u624b\u6bb5\u4e4b\u4e00&#xff1a; <\/p>\n<p>ulimit -n 65535<\/p>\n<p> \u8be5\u547d\u4ee4\u8bbe\u7f6e\u7cfb\u7edf\u5141\u8bb8\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\u4e3a65535&#xff0c;\u4ee5\u786e\u4fdd\u5728\u9ad8\u5e76\u53d1\u4e0b\u7cfb\u7edf\u4e0d\u4f1a\u56e0\u6587\u4ef6\u53e5\u67c4\u8017\u5c3d\u800c\u51fa\u73b0\u95ee\u9898\u3002 <\/p>\n<h3> 3.3 SAPI\u7684\u5b89\u5168\u6027\u63d0\u5347\u63aa\u65bd <\/h3>\n<h4> 3.3.1 \u5b89\u5168\u6f0f\u6d1e\u4e0e\u9632\u8303 <\/h4>\n<p> \u5b89\u5168\u662fSAPI\u5e94\u7528\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\u3002\u5728Web\u5f00\u53d1\u8fc7\u7a0b\u4e2d&#xff0c;\u7531\u4e8eSAPI\u7684\u76f4\u63a5\u66b4\u9732\u4e8e\u5916\u90e8\u7f51\u7edc&#xff0c;\u5bb9\u6613\u6210\u4e3a\u653b\u51fb\u8005\u7684\u653b\u51fb\u76ee\u6807\u3002\u56e0\u6b64&#xff0c;\u53ca\u65f6\u53d1\u73b0\u548c\u4fee\u590d\u5b89\u5168\u6f0f\u6d1e\u81f3\u5173\u91cd\u8981\u3002 <\/p>\n<p> PHP\u7684\u5e38\u89c1\u5b89\u5168\u6f0f\u6d1e\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>  \u8fdc\u7a0b\u4ee3\u7801\u6267\u884c&#xff08;RCE&#xff09;  &#xff1a;\u901a\u8fc7\u672a\u8fc7\u6ee4\u7684\u8f93\u5165\u53c2\u6570&#xff0c;\u653b\u51fb\u8005\u53ef\u4ee5\u6267\u884c\u4efb\u610f\u4ee3\u7801\u3002 <\/li>\n<li>\n<p>  SQL\u6ce8\u5165  &#xff1a;\u672a\u7ecf\u8fc7\u6ee4\u7684\u7528\u6237\u8f93\u5165\u76f4\u63a5\u62fc\u63a5\u5230SQL\u67e5\u8be2\u4e2d&#xff0c;\u53ef\u80fd\u4f1a\u88ab\u5229\u7528\u6267\u884c\u6076\u610fSQL\u547d\u4ee4\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u8de8\u7ad9\u811a\u672c\u653b\u51fb&#xff08;XSS&#xff09;  &#xff1a;\u5728\u7f51\u9875\u4e2d\u6ce8\u5165\u6076\u610f\u811a\u672c\u4ee3\u7801&#xff0c;\u5f71\u54cd\u8bbf\u95ee\u8005\u7684\u6d4f\u89c8\u5668\u884c\u4e3a\u3002 <\/p>\n<\/li>\n<\/ul>\n<p> \u4e3a\u4e86\u9632\u8303\u8fd9\u4e9b\u5b89\u5168\u6f0f\u6d1e&#xff0c;\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u63aa\u65bd&#xff1a; <\/p>\n<ul>\n<li>  \u4f7f\u7528\u5b89\u5168\u6269\u5c55  &#xff1a;\u5982  Suhosin  &#xff0c;\u4e3aPHP\u63d0\u4f9b\u989d\u5916\u7684\u5b89\u5168\u5c42\u3002 <\/li>\n<li>\n<p>  \u53c2\u6570\u5316\u67e5\u8be2  &#xff1a;\u4f7f\u7528\u6570\u636e\u5e93\u7684\u9884\u5904\u7406\u8bed\u53e5\u6216\u53c2\u6570\u5316\u67e5\u8be2\u9632\u6b62SQL\u6ce8\u5165\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u5185\u5bb9\u5b89\u5168\u7b56\u7565&#xff08;CSP&#xff09;  &#xff1a;\u5728HTTP\u54cd\u5e94\u4e2d\u8bbe\u7f6eCSP\u5934&#xff0c;\u9650\u5236\u8d44\u6e90\u52a0\u8f7d\u7b56\u7565&#xff0c;\u51cf\u5c11XSS\u653b\u51fb\u7684\u53ef\u80fd\u6027\u3002 <\/p>\n<\/li>\n<\/ul>\n<h4> 3.3.2 \u5b89\u5168\u5b9e\u8df5\u4e0e\u6700\u4f73\u505a\u6cd5 <\/h4>\n<p> \u6267\u884c\u5b89\u5168\u5b9e\u8df5\u548c\u6700\u4f73\u505a\u6cd5\u80fd\u663e\u8457\u63d0\u5347SAPI\u5e94\u7528\u7684\u5b89\u5168\u6c34\u5e73\u3002\u8fd9\u4e9b\u63aa\u65bd\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>\n<p>  \u4f7f\u7528HTTPS  &#xff1a;\u5bf9\u6240\u6709\u4f20\u8f93\u6570\u636e\u8fdb\u884c\u52a0\u5bc6&#xff0c;\u907f\u514d\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u622a\u83b7\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u5b89\u5168\u7f16\u7801  &#xff1a;\u9075\u5b88\u5b89\u5168\u7f16\u7801\u6807\u51c6&#xff0c;\u6bd4\u5982\u8f93\u5165\u9a8c\u8bc1\u3001\u8f93\u51fa\u7f16\u7801\u4ee5\u53ca\u4f7f\u7528\u5b89\u5168API\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u6700\u5c0f\u6743\u9650\u539f\u5219  &#xff1a;\u4e3aSAPI\u8fdb\u7a0b\u914d\u7f6e\u6700\u5c0f\u5fc5\u8981\u7684\u6743\u9650&#xff0c;\u9632\u6b62\u6743\u9650\u6ee5\u7528\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u5b9a\u671f\u66f4\u65b0\u548c\u6253\u8865\u4e01  &#xff1a;\u53ca\u65f6\u66f4\u65b0PHP\u548cWeb\u670d\u52a1\u5668\u8f6f\u4ef6&#xff0c;\u5e94\u7528\u5b89\u5168\u8865\u4e01\u3002 <\/p>\n<\/li>\n<li>\n<p>  \u5b89\u5168\u914d\u7f6e\u5ba1\u6838  &#xff1a;\u5b9a\u671f\u68c0\u67e5\u670d\u52a1\u5668\u914d\u7f6e&#xff0c;\u786e\u4fdd\u6ca1\u6709\u4e0d\u5fc5\u8981\u7684\u670d\u52a1\u548c\u7aef\u53e3\u66b4\u9732\u3002 <\/p>\n<\/li>\n<\/ul>\n<p> \u9075\u5faa\u4e0a\u8ff0\u7684\u5b89\u5168\u5b9e\u8df5&#xff0c;\u53ef\u4ee5\u6709\u6548\u51cf\u5c11SAPI\u5e94\u7528\u7684\u5b89\u5168\u98ce\u9669&#xff0c;\u786e\u4fddWeb\u5e94\u7528\u7684\u5b89\u5168\u7a33\u5b9a\u8fd0\u884c\u3002 <\/p>\n<h3> \u8868\u683c\u4e0e\u6d41\u7a0b\u56fe\u5c55\u793a <\/h3>\n<h4> SAPI\u5b89\u5168\u7279\u6027\u6bd4\u8f83 <\/h4>\n<table>\n<tr> SAPI\u7c7b\u578b  \u5b89\u5168\u7279\u6027\u652f\u6301  \u914d\u7f6e\u590d\u6742\u5ea6  \u6027\u80fd\u5f71\u54cd <\/tr>\n<tbody>\n<tr>\n<td> mod_php <\/td>\n<td> \u8f83\u4f4e <\/td>\n<td> \u7b80\u5355 <\/td>\n<td> \u8f83\u9ad8 <\/td>\n<\/tr>\n<tr>\n<td> php-cgi <\/td>\n<td> \u4e2d\u7b49 <\/td>\n<td> \u4e2d\u7b49 <\/td>\n<td> \u4e2d\u7b49 <\/td>\n<\/tr>\n<tr>\n<td> php-fpm <\/td>\n<td> \u8f83\u9ad8 <\/td>\n<td> \u590d\u6742 <\/td>\n<td> \u8f83\u4f4e <\/td>\n<\/tr>\n<tr>\n<td> CLI <\/td>\n<td> \u9ad8 <\/td>\n<td> \u7b80\u5355 <\/td>\n<td> \u4f4e <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4> \u6027\u80fd\u4f18\u5316\u6d41\u7a0b\u56fe <\/h4>\n<p>graph TD<br \/>\n    A[\u5f00\u59cb\u6027\u80fd\u4f18\u5316] &#8211;&gt; B[\u76d1\u63a7PHP\u548cWeb\u670d\u52a1\u5668\u6027\u80fd]<br \/>\n    B &#8211;&gt; C[\u5206\u6790\u6162\u67e5\u8be2\u548c\u6027\u80fd\u74f6\u9888]<br \/>\n    C &#8211;&gt; D[\u8c03\u6574PHP\u914d\u7f6e\u53c2\u6570]<br \/>\n    D &#8211;&gt; E[\u4f18\u5316\u4ee3\u7801\u548c\u6570\u636e\u5e93\u67e5\u8be2]<br \/>\n    E &#8211;&gt; F[\u6d4b\u8bd5\u4f18\u5316\u6548\u679c]<br \/>\n    F &#8211;&gt; G{\u662f\u5426\u6ee1\u8db3\u6027\u80fd\u8981\u6c42?}<br \/>\n    G &#8212; \u662f &#8211;&gt; H[\u6301\u7eed\u76d1\u63a7\u548c\u5fae\u8c03]<br \/>\n    G &#8212; \u5426 &#8211;&gt; I[\u8fdb\u4e00\u6b65\u5206\u6790\u4e0e\u4f18\u5316]<br \/>\n    H &#8211;&gt; J[\u7ed3\u675f\u6027\u80fd\u4f18\u5316]<br \/>\n    I &#8211;&gt; B<\/p>\n<p> \u4ee5\u4e0a\u8868\u683c\u63d0\u4f9b\u4e86\u4e0d\u540cSAPI\u7c7b\u578b\u5b89\u5168\u7279\u6027\u652f\u6301\u3001\u914d\u7f6e\u590d\u6742\u5ea6\u4ee5\u53ca\u5bf9\u6027\u80fd\u5f71\u54cd\u7684\u5feb\u901f\u6bd4\u8f83\u3002\u800c\u6d41\u7a0b\u56fe\u63cf\u8ff0\u4e86\u4ece\u5f00\u59cb\u6027\u80fd\u4f18\u5316\u5230\u7ed3\u675f\u7684\u6574\u4e2a\u8fc7\u7a0b&#xff0c;\u5305\u62ec\u76d1\u63a7\u3001\u5206\u6790\u3001\u914d\u7f6e\u3001\u6d4b\u8bd5\u548c\u5fae\u8c03\u7b49\u5173\u952e\u6b65\u9aa4\u3002\u8fd9\u4e9b\u5de5\u5177\u548c\u7b56\u7565\u53ef\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u63d0\u9ad8SAPI\u7684\u517c\u5bb9\u6027\u3001\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002 <\/p>\n<h2> 4. \u5e38\u89c1SAPI\u7c7b\u578b\u793a\u4f8b <\/h2>\n<h3> 4.1 mod_php\u7684\u4f7f\u7528\u4e0e\u914d\u7f6e <\/h3>\n<h4> 4.1.1 Apache\u96c6\u6210\u7684mod_php\u5b89\u88c5\u4e0e\u8bbe\u7f6e <\/h4>\n<p> Apache\u662f\u4e16\u754c\u4e0a\u6700\u6d41\u884c\u7684Web\u670d\u52a1\u5668\u4e4b\u4e00&#xff0c;\u800cmod_php\u662fApache\u7684\u4e00\u4e2a\u6a21\u5757&#xff0c;\u5141\u8bb8Apache\u670d\u52a1\u5668\u76f4\u63a5\u6267\u884cPHP\u4ee3\u7801\u3002\u8fd9\u79cd\u96c6\u6210\u65b9\u5f0f\u63d0\u4f9b\u4e86\u6027\u80fd\u4e0a\u7684\u4f18\u52bf&#xff0c;\u56e0\u4e3aPHP\u4ee3\u7801\u4e0eApache\u8fdb\u7a0b\u5728\u540c\u4e00\u4e2a\u5185\u5b58\u7a7a\u95f4\u5185\u6267\u884c&#xff0c;\u51cf\u5c11\u4e86\u8fdb\u7a0b\u95f4\u901a\u4fe1\u7684\u5f00\u9500\u3002 <\/p>\n<p> \u8981\u5b89\u88c5\u548c\u914d\u7f6emod_php&#xff0c;\u901a\u5e38\u9700\u8981\u7f16\u8bd1\u5b89\u88c5Apache\u4ee5\u53camod_php\u6a21\u5757&#xff0c;\u6216\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u88c5\u3002\u4ee5\u4e0b\u662f\u5728Linux\u73af\u5883\u4e0b\u4f7f\u7528yum\u8fdb\u884c\u5b89\u88c5\u7684\u793a\u4f8b\u4ee3\u7801\u5757&#xff1a; <\/p>\n<p>sudo yum install httpd php php-common<br \/>\nsudo systemctl enable httpd<br \/>\nsudo systemctl start httpd<\/p>\n<p> \u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u60a8\u9700\u8981\u914d\u7f6eApache\u4ee5\u542f\u7528PHP\u652f\u6301\u3002\u8fd9\u901a\u5e38\u6d89\u53ca\u7f16\u8f91Apache\u914d\u7f6e\u6587\u4ef6  httpd.conf  &#xff0c;\u5e76\u786e\u4fdd\u5305\u542b\u4ee5\u4e0b\u6307\u4ee4&#xff1a; <\/p>\n<p>LoadModule php7_module modules\/libphp7.so<br \/>\nAddHandler application\/x-httpd-php .php<br \/>\nDirectoryIndex index.html index.php<\/p>\n<p> \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;  LoadModule  \u6307\u4ee4\u52a0\u8f7dPHP\u6a21\u5757&#xff0c;  AddHandler  \u6307\u4ee4\u5c06  .php  \u6587\u4ef6\u4e0ePHP\u5904\u7406\u7a0b\u5e8f\u5173\u8054&#xff0c;\u800c  DirectoryIndex  \u6307\u4ee4\u6307\u5b9a\u5f53\u8bf7\u6c42\u76ee\u5f55\u65f6&#xff0c;\u9ed8\u8ba4\u7684\u7d22\u5f15\u6587\u4ef6\u3002 <\/p>\n<h4> 4.1.2 \u6a21\u5757\u8fd0\u884c\u673a\u5236\u4e0e\u6027\u80fd\u7279\u70b9 <\/h4>\n<p> mod_php\u6a21\u5757\u5728Apache\u8fdb\u7a0b\u542f\u52a8\u65f6\u521d\u59cb\u5316&#xff0c;\u5e76\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u7684PHP\u89e3\u6790\u5668\u3002\u8fd9\u610f\u5473\u7740\u65e0\u9700\u521b\u5efa\u5b50\u8fdb\u7a0b&#xff0c;\u4ece\u800c\u51cf\u5c11\u4e86\u5185\u5b58\u6d88\u8017&#xff0c;\u5e76\u4e14\u80fd\u591f\u5feb\u901f\u5904\u7406\u8bf7\u6c42\u3002\u7136\u800c&#xff0c;\u6bcf\u4e2aApache\u8fdb\u7a0b\u90fd\u52a0\u8f7d\u4e86\u6574\u4e2aPHP\u73af\u5883&#xff0c;\u8fd9\u53ef\u80fd\u5bfc\u81f4\u8d44\u6e90\u4f7f\u7528\u7387\u8f83\u9ad8&#xff0c;\u7279\u522b\u662f\u5728\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\u65f6\u3002 <\/p>\n<p> mod_php\u6027\u80fd\u7279\u70b9\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>  \u542f\u52a8\u901f\u5ea6\u5feb  &#xff1a;\u7531\u4e8ePHP\u73af\u5883\u5df2\u7ecf\u4e0eApache\u8fdb\u7a0b\u7ed1\u5b9a&#xff0c;\u56e0\u6b64\u5bf9\u8bf7\u6c42\u7684\u54cd\u5e94\u901a\u5e38\u975e\u5e38\u5feb\u3002 <\/li>\n<li>  \u8d44\u6e90\u5360\u7528\u5927  &#xff1a;\u6bcf\u4e2aApache\u8fdb\u7a0b\u90fd\u9700\u8981\u81ea\u5df1\u7684PHP\u73af\u5883\u526f\u672c&#xff0c;\u8fd9\u5728\u9ad8\u6d41\u91cf\u7f51\u7ad9\u4e0a\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8d44\u6e90\u4e0d\u8db3\u3002 <\/li>\n<li>  \u6613\u7528\u6027\u9ad8  &#xff1a;\u65e0\u9700\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u542f\u52a8\u65b0\u7684\u5b50\u8fdb\u7a0b&#xff0c;\u8fd9\u7b80\u5316\u4e86\u914d\u7f6e\u548c\u7ba1\u7406\u3002 <\/li>\n<\/ul>\n<p> \u9488\u5bf9\u8fd9\u4e9b\u7279\u70b9&#xff0c;mod_php\u9002\u7528\u4e8e\u8f83\u5c0f\u89c4\u6a21\u7684Web\u5e94\u7528&#xff0c;\u6216\u8005\u5bf9\u6027\u80fd\u8981\u6c42\u4e0d\u662f\u7279\u522b\u9ad8\u7684\u573a\u666f\u3002\u7136\u800c&#xff0c;\u5728\u9700\u8981\u9ad8\u5e76\u53d1\u548c\u4f4e\u8d44\u6e90\u6d88\u8017\u7684\u573a\u5408&#xff0c;mod_php\u53ef\u80fd\u4e0d\u662f\u6700\u4f73\u9009\u62e9\u3002 <\/p>\n<h3> 4.2 php-cgi\u7684\u8fd0\u884c\u673a\u5236 <\/h3>\n<h4> 4.2.1 CGI\u534f\u8bae\u7684\u5de5\u4f5c\u539f\u7406 <\/h4>\n<p> CGI&#xff08;Common Gateway Interface&#xff09;\u662f\u4e00\u79cd\u53e4\u8001\u7684Web\u670d\u52a1\u5668\u63a5\u53e3\u6807\u51c6&#xff0c;\u5b83\u5141\u8bb8Web\u670d\u52a1\u5668\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u6765\u5904\u7406\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u3002php-cgi\u662fPHP\u7684CGI\u7248\u672c&#xff0c;\u5b83\u53ef\u4ee5\u88abWeb\u670d\u52a1\u5668\u7528\u6765\u6267\u884cPHP\u4ee3\u7801\u3002 <\/p>\n<p> CGI\u534f\u8bae\u7684\u4e3b\u8981\u5de5\u4f5c\u539f\u7406\u662f&#xff1a; <\/p>\n<li> Web\u670d\u52a1\u5668\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42&#xff0c;\u786e\u5b9a\u9700\u8981\u901a\u8fc7CGI\u5904\u7406\u3002 <\/li>\n<li> \u670d\u52a1\u5668\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u542f\u52a8\u4e00\u4e2aCGI\u8fdb\u7a0b\u3002 <\/li>\n<li> CGI\u8fdb\u7a0b\u6267\u884cPHP\u89e3\u91ca\u5668\u6765\u89e3\u91ca\u548c\u6267\u884cPHP\u4ee3\u7801\u3002 <\/li>\n<li> \u6267\u884c\u7ed3\u679c\u8fd4\u56de\u7ed9Web\u670d\u52a1\u5668&#xff0c;\u7136\u540e\u670d\u52a1\u5668\u5c06\u5176\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002 <\/li>\n<h4> 4.2.2 php-cgi\u4e0eWeb\u670d\u52a1\u5668\u7684\u4ea4\u4e92 <\/h4>\n<p> Web\u670d\u52a1\u5668\u4e0ephp-cgi\u7684\u4ea4\u4e92\u9700\u8981\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u548c\u547d\u4ee4\u884c\u53c2\u6570\u6765\u5b8c\u6210\u3002\u670d\u52a1\u5668\u5c06HTTP\u8bf7\u6c42\u7684\u4fe1\u606f\u8f6c\u6362\u4e3aCGI\u73af\u5883\u53d8\u91cf&#xff0c;\u5e76\u5c06\u8bf7\u6c42\u6570\u636e\u4f20\u9012\u7ed9php-cgi\u8fdb\u7a0b\u3002php-cgi\u8fdb\u7a0b\u5219\u8d1f\u8d23\u5904\u7406\u8bf7\u6c42\u5e76\u8fd4\u56de\u54cd\u5e94\u3002 <\/p>\n<p> \u4e3a\u4e86\u4f7f\u7528php-cgi&#xff0c;Web\u670d\u52a1\u5668\u9700\u8981\u5728\u5176\u914d\u7f6e\u4e2d\u6307\u5b9aCGI\u5904\u7406\u7a0b\u5e8f\u7684\u8def\u5f84\u3002\u4f8b\u5982&#xff0c;\u5728Apache\u4e2d&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u914d\u7f6e\u6307\u5b9aphp-cgi\u7684\u6267\u884c\u8def\u5f84&#xff1a; <\/p>\n<p>Action application\/x-httpd-php \/cgi-bin\/php-cgi<br \/>\nAddHandler application\/x-httpd-php .php<\/p>\n<p> \u6b64\u914d\u7f6e\u5c06\u6240\u6709  .php  \u6587\u4ef6\u8bf7\u6c42\u8f6c\u53d1\u7ed9  \/cgi-bin\/php-cgi  \u811a\u672c\u5904\u7406\u3002\u7136\u800c&#xff0c;\u7531\u4e8ephp-cgi\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u521b\u5efa\u4e00\u4e2a\u65b0\u8fdb\u7a0b&#xff0c;\u56e0\u6b64\u8fd9\u79cd\u914d\u7f6e\u65b9\u5f0f\u7684\u6027\u80fd\u5f00\u9500\u8f83\u5927&#xff0c;\u4e0d\u63a8\u8350\u5728\u9ad8\u8d1f\u8f7d\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u4f7f\u7528\u3002 <\/p>\n<h3> 4.3 php-fpm\u7684\u4f18\u52bf\u4e0e\u5e94\u7528\u573a\u666f <\/h3>\n<h4> 4.3.1 FPM\u7684\u5de5\u4f5c\u539f\u7406\u53ca\u4f18\u52bf <\/h4>\n<p> php-fpm&#xff08;FastCGI Process Manager&#xff09;\u662f\u4e00\u4e2aPHP FastCGI\u5b9e\u73b0&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u8fdb\u7a0b\u7ba1\u7406\u7684\u529f\u80fd\u3002\u4e0e\u4f20\u7edf\u7684CGI\u6216mod_php\u76f8\u6bd4&#xff0c;php-fpm\u66f4\u9002\u5408\u5904\u7406\u9ad8\u5e76\u53d1\u8bf7\u6c42&#xff0c;\u56e0\u4e3a\u5b83\u80fd\u591f\u7ba1\u7406\u4e00\u7ec4PHP\u8fdb\u7a0b&#xff0c;\u5e76\u52a8\u6001\u5730\u5206\u914d\u5de5\u4f5c\u8d1f\u8f7d\u3002 <\/p>\n<p> php-fpm\u7684\u5de5\u4f5c\u539f\u7406\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>  \u76d1\u542c\u7aef\u53e3\u6216Unix\u5957\u63a5\u5b57  &#xff1a;php-fpm\u5728\u6307\u5b9a\u7684\u7aef\u53e3\u6216Unix\u5957\u63a5\u5b57\u4e0a\u76d1\u542c\u6765\u81eaWeb\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u3002 <\/li>\n<li>  \u8fdb\u7a0b\u6c60  &#xff1a;\u7ef4\u62a4\u4e00\u4e2a\u8fdb\u7a0b\u6c60&#xff0c;\u6839\u636e\u914d\u7f6e\u7684\u4e0d\u540c&#xff0c;\u53ef\u4ee5\u6709\u591a\u4e2a\u5b50\u8fdb\u7a0b\u3002 <\/li>\n<li>  \u8bf7\u6c42\u8c03\u5ea6  &#xff1a;php-fpm\u6839\u636e\u7279\u5b9a\u7b97\u6cd5\u5c06\u8bf7\u6c42\u5206\u53d1\u7ed9\u7a7a\u95f2\u8fdb\u7a0b\u5904\u7406\u3002 <\/li>\n<li>  \u52a8\u6001\u8c03\u6574  &#xff1a;php-fpm\u53ef\u4ee5\u6839\u636e\u8d1f\u8f7d\u52a8\u6001\u5730\u589e\u52a0\u6216\u51cf\u5c11\u5de5\u4f5c\u8fdb\u7a0b\u7684\u6570\u91cf\u3002 <\/li>\n<\/ul>\n<p> php-fpm\u7684\u4f18\u52bf\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>  \u9ad8\u6548\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42  &#xff1a;\u901a\u8fc7\u8fdb\u7a0b\u6c60\u548c\u8bf7\u6c42\u8c03\u5ea6&#xff0c;php-fpm\u80fd\u591f\u5feb\u901f\u54cd\u5e94\u5e76\u53d1\u8bf7\u6c42\u3002 <\/li>\n<li>  \u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879  &#xff1a;php-fpm\u63d0\u4f9b\u4e86\u591a\u79cd\u914d\u7f6e\u9009\u9879&#xff0c;\u5141\u8bb8\u7ec6\u81f4\u5730\u8c03\u6574\u5de5\u4f5c\u8fdb\u7a0b\u7684\u884c\u4e3a\u3002 <\/li>\n<li>  \u8d44\u6e90\u5229\u7528\u4f18\u5316  &#xff1a;\u80fd\u591f\u6839\u636e\u9700\u8981\u52a8\u6001\u8c03\u6574\u8fdb\u7a0b\u6570&#xff0c;\u907f\u514d\u4e86\u8d44\u6e90\u6d6a\u8d39\u3002 <\/li>\n<\/ul>\n<h4> 4.3.2 php-fpm\u7684\u6027\u80fd\u4f18\u5316\u5b9e\u8df5 <\/h4>\n<p> \u4e3a\u4e86\u83b7\u5f97php-fpm\u7684\u6700\u4f73\u6027\u80fd&#xff0c;\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u9002\u5f53\u7684\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6027\u80fd\u4f18\u5316\u5b9e\u8df5&#xff1a; <\/p>\n<ul>\n<li>  \u8fdb\u7a0b\u7ba1\u7406  &#xff1a;\u8c03\u6574  pm.max_children  \u53c2\u6570\u6765\u8bbe\u5b9a\u6700\u5927\u5b50\u8fdb\u7a0b\u6570&#xff0c;  pm.start_servers  \u6765\u8bbe\u7f6e\u542f\u52a8\u65f6\u7684\u8fdb\u7a0b\u6570&#xff0c;\u4ee5\u53ca  pm.min_spare_servers  \u548c  pm.max_spare_servers  \u6765\u8bbe\u7f6e\u7a7a\u95f2\u8fdb\u7a0b\u7684\u6700\u5c0f\u548c\u6700\u5927\u6570\u91cf\u3002 <\/li>\n<li>  \u8bf7\u6c42\u5904\u7406\u65f6\u95f4  &#xff1a;\u901a\u8fc7  request_terminate_timeout  \u53c2\u6570\u6765\u8bbe\u7f6e\u811a\u672c\u7684\u6700\u5927\u6267\u884c\u65f6\u95f4&#xff0c;\u9632\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u811a\u672c\u6d88\u8017\u8fc7\u591a\u8d44\u6e90\u3002 <\/li>\n<li>  \u9519\u8bef\u65e5\u5fd7\u7ba1\u7406  &#xff1a;\u901a\u8fc7  log_level  \u548c  error_log  \u53c2\u6570\u63a7\u5236\u9519\u8bef\u65e5\u5fd7\u7684\u8be6\u7ec6\u7a0b\u5ea6\u548c\u5b58\u50a8\u4f4d\u7f6e\u3002 <\/li>\n<\/ul>\n<p>[global]<br \/>\npm &#061; dynamic<br \/>\npm.max_children &#061; 10<br \/>\npm.start_servers &#061; 3<br \/>\npm.min_spare_servers &#061; 1<br \/>\npm.max_spare_servers &#061; 5<br \/>\nrequest_terminate_timeout &#061; 30s<br \/>\nlog_level &#061; notice<br \/>\nerror_log &#061; \/var\/log\/php-fpm.log<\/p>\n<p> \u8fd9\u53ea\u662f\u4e00\u4e2a\u793a\u4f8b\u914d\u7f6e&#xff0c;\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u914d\u7f6e\u4f1a\u6839\u636e\u670d\u52a1\u5668\u7684\u6027\u80fd\u548c\u5e94\u7528\u9700\u6c42\u6709\u6240\u4e0d\u540c\u3002 <\/p>\n<h3> 4.4 CLI SAPI\u7684\u7279\u70b9\u4e0e\u7528\u9014 <\/h3>\n<h4> 4.4.1 \u547d\u4ee4\u884c\u73af\u5883\u4e0bPHP\u7684\u5e94\u7528\u573a\u666f <\/h4>\n<p> CLI&#xff08;Command Line Interface&#xff09;\u662fPHP\u7684\u547d\u4ee4\u884cSAPI&#xff08;Server API&#xff09;&#xff0c;\u5b83\u53ef\u4ee5\u8fd0\u884c\u5728\u4e0d\u901a\u8fc7Web\u670d\u52a1\u5668\u7684\u73af\u5883\u4e2d&#xff0c;\u76f4\u63a5\u5728\u64cd\u4f5c\u7cfb\u7edf\u547d\u4ee4\u884c\u4e2d\u6267\u884cPHP\u811a\u672c\u3002CLI SAPI\u975e\u5e38\u9002\u5408\u540e\u53f0\u4efb\u52a1\u5904\u7406\u3001\u811a\u672c\u81ea\u52a8\u5316\u4ee5\u53ca\u547d\u4ee4\u884c\u5de5\u5177\u5f00\u53d1\u3002 <\/p>\n<p> CLI SAPI\u5728Linux\u73af\u5883\u4e0b\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u8c03\u7528php\u547d\u4ee4\u6765\u6267\u884c\u811a\u672c&#xff0c;\u4f8b\u5982&#xff1a; <\/p>\n<p>php script.php<\/p>\n<p> CLI SAPI\u7684\u7279\u70b9\u5305\u62ec&#xff1a; <\/p>\n<ul>\n<li>  \u72ec\u7acb\u6267\u884c  &#xff1a;\u4e0d\u9700\u8981Web\u670d\u52a1\u5668\u7684\u53c2\u4e0e&#xff0c;\u76f4\u63a5\u7531PHP\u89e3\u91ca\u5668\u5904\u7406\u3002 <\/li>\n<li>  \u6279\u5904\u7406\u811a\u672c  &#xff1a;\u975e\u5e38\u9002\u5408\u6267\u884c\u5b9a\u671f\u6267\u884c\u7684\u811a\u672c\u4efb\u52a1&#xff0c;\u4f8b\u5982\u6570\u636e\u5907\u4efd\u3001\u6570\u636e\u540c\u6b65\u7b49\u3002 <\/li>\n<li>  \u4ea4\u4e92\u5f0f\u4f7f\u7528  &#xff1a;\u53ef\u4ee5\u901a\u8fc7\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u4e0e\u7528\u6237\u4ea4\u4e92&#xff0c;\u65b9\u4fbf\u5f00\u53d1\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u5de5\u5177\u3002 <\/li>\n<\/ul>\n<h4> 4.4.2 CLI SAPI\u7684\u914d\u7f6e\u4e0e\u4f18\u5316 <\/h4>\n<p> \u5728CLI\u73af\u5883\u4e2d&#xff0c;\u901a\u5e38\u4e0d\u9700\u8981\u5bf9PHP\u8fdb\u884c\u7279\u522b\u7684\u914d\u7f6e\u3002\u7136\u800c&#xff0c;\u5982\u679c\u5e0c\u671b\u5bf9CLI SAPI\u8fdb\u884c\u4f18\u5316&#xff0c;\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762&#xff1a; <\/p>\n<ul>\n<li>  \u5185\u5b58\u9650\u5236  &#xff1a;CLI\u6267\u884c\u7684\u811a\u672c\u901a\u5e38\u4e0d\u53d7\u5185\u5b58\u9650\u5236\u7684\u7ea6\u675f&#xff0c;\u4f46\u53ef\u4ee5\u901a\u8fc7  memory_limit  \u53c2\u6570\u6765\u9650\u5236\u811a\u672c\u6d88\u8017\u7684\u5185\u5b58\u3002 <\/li>\n<li>  \u6267\u884c\u65f6\u95f4\u9650\u5236  &#xff1a;\u4f7f\u7528  max_execution_time  \u53c2\u6570\u6765\u9650\u5236\u811a\u672c\u6267\u884c\u7684\u6700\u5927\u65f6\u95f4\u3002 <\/li>\n<li>  \u9519\u8bef\u8f93\u51fa  &#xff1a;\u4f7f\u7528  &#8211;debug  \u6216  &#8211;info  \u9009\u9879\u6765\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u6216\u8fd0\u884c\u65f6\u4fe1\u606f\u3002 <\/li>\n<\/ul>\n<p>php &#8211;info<\/p>\n<p> \u4ee5\u4e0a\u547d\u4ee4\u4f1a\u63d0\u4f9b\u5f53\u524dCLI\u73af\u5883\u4e0b\u7684PHP\u914d\u7f6e\u4fe1\u606f&#xff0c;\u6709\u52a9\u4e8e\u5f00\u53d1\u8005\u4e86\u89e3\u5f53\u524d\u73af\u5883&#xff0c;\u5e76\u636e\u6b64\u8fdb\u884c\u4f18\u5316\u3002 <\/p>\n<p> CLI SAPI\u7684\u914d\u7f6e\u548c\u4f18\u5316\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u811a\u672c\u548c\u4efb\u52a1\u9700\u6c42\u6765\u8fdb\u884c&#xff0c;\u4ee5\u786e\u4fdd\u811a\u672c\u7684\u9ad8\u6548\u6267\u884c\u3002\u7531\u4e8eCLI\u73af\u5883\u4e0b\u6ca1\u6709Web\u670d\u52a1\u5668\u7684\u5f00\u9500&#xff0c;\u56e0\u6b64\u901a\u5e38\u80fd\u591f\u63d0\u4f9b\u6bd4\u5176\u4ed6SAPI\u7c7b\u578b\u66f4\u9ad8\u7684\u6027\u80fd\u3002 <\/p>\n<h2> 5. \u9009\u62e9SAPI\u7684\u8003\u91cf\u56e0\u7d20 <\/h2>\n<p> \u5728\u8fdb\u884cPHP\u5f00\u53d1\u65f6&#xff0c;\u9009\u62e9\u5408\u9002\u7684SAPI\u5bf9\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u6210\u529f\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u9009\u62e9SAPI\u65f6\u9700\u8981\u8003\u8651\u7684\u51e0\u4e2a\u5173\u952e\u56e0\u7d20\u3002 <\/p>\n<h3> 5.1 \u90e8\u7f72\u73af\u5883\u5bf9SAPI\u9009\u62e9\u7684\u5f71\u54cd <\/h3>\n<p> \u5728\u9009\u62e9SAPI\u65f6&#xff0c;\u9996\u5148\u8981\u8003\u8651\u7684\u662f\u90e8\u7f72\u73af\u5883\u3002\u90e8\u7f72\u73af\u5883\u5305\u62ec\u670d\u52a1\u5668\u7c7b\u578b\u3001\u7cfb\u7edf\u8d44\u6e90\u548c\u6027\u80fd\u8981\u6c42\u7b49\u3002 <\/p>\n<h4> 5.1.1 \u670d\u52a1\u5668\u7c7b\u578b\u4e0eSAPI\u7684\u9009\u62e9 <\/h4>\n<p> \u4e0d\u540c\u7684Web\u670d\u52a1\u5668\u5bf9SAPI\u7684\u652f\u6301\u4e5f\u6709\u6240\u4e0d\u540c\u3002\u4f8b\u5982&#xff1a; <\/p>\n<ul>\n<li> Apache\u670d\u52a1\u5668\u53ef\u4ee5\u4f7f\u7528mod_php\u6216php-fpm\u3002 <\/li>\n<li> Nginx\u670d\u52a1\u5668\u5219\u901a\u5e38\u4e0ephp-fpm\u642d\u914d\u4f7f\u7528\u3002 <\/li>\n<li> \u8f7b\u91cf\u7ea7\u670d\u52a1\u5668\u5982lighttpd\u53ef\u80fd\u66f4\u9002\u5408\u4f7f\u7528php-cgi\u6216FastCGI\u3002 <\/li>\n<\/ul>\n<h4> 5.1.2 \u7cfb\u7edf\u8d44\u6e90\u4e0e\u6027\u80fd\u8981\u6c42 <\/h4>\n<p> SAPI\u7c7b\u578b\u5bf9\u7cfb\u7edf\u8d44\u6e90\u7684\u5f71\u54cd\u4e5f\u5e94\u6210\u4e3a\u8003\u8651\u56e0\u7d20\u3002\u4f8b\u5982&#xff0c;mod_php\u5728Apache\u4e2d\u901a\u5e38\u4f1a\u5360\u7528\u66f4\u591a\u5185\u5b58&#xff0c;\u56e0\u4e3a\u5b83\u5728\u6bcf\u4e2a\u8bf7\u6c42\u4e2d\u90fd\u4f1a\u52a0\u8f7d\u6574\u4e2aPHP\u73af\u5883\u3002\u76f8\u6bd4\u4e4b\u4e0b&#xff0c;php-fpm\u6216php-cgi\u5219\u5141\u8bb8\u591a\u4e2aPHP\u8fdb\u7a0b\u5171\u4eab\u76f8\u540c\u7684\u5185\u5b58\u7a7a\u95f4&#xff0c;\u53ef\u80fd\u66f4\u9002\u5408\u5185\u5b58\u53d7\u9650\u7684\u73af\u5883\u3002 <\/p>\n<h3> 5.2 \u5e94\u7528\u9700\u6c42\u4e0eSAPI\u9002\u914d\u6027\u5206\u6790 <\/h3>\n<p> \u6839\u636e\u5e94\u7528\u7684\u7279\u5b9a\u9700\u6c42\u548c\u6d41\u91cf\u60c5\u51b5&#xff0c;\u9009\u62e9\u5408\u9002\u7684SAPI\u540c\u6837\u91cd\u8981\u3002 <\/p>\n<h4> 5.2.1 \u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684SAPI\u9009\u62e9 <\/h4>\n<p> \u5728\u9ad8\u5e76\u53d1\u7684\u573a\u666f\u4e0b&#xff0c;\u5982\u4f7f\u7528php-fpm\u4f5c\u4e3aSAPI&#xff0c;\u901a\u5e38\u80fd\u591f\u63d0\u4f9b\u66f4\u4f73\u7684\u6027\u80fd\u3002\u8fd9\u662f\u56e0\u4e3aphp-fpm\u652f\u6301\u8fdb\u7a0b\u6c60&#xff0c;\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u591a\u4e2a\u5de5\u4f5c\u8fdb\u7a0b&#xff0c;\u63d0\u9ad8\u5904\u7406\u5e76\u53d1\u8bf7\u6c42\u7684\u80fd\u529b\u3002 <\/p>\n<h4> 5.2.2 SAPI\u4e0e\u7279\u5b9a\u5e94\u7528\u6846\u67b6\u7684\u517c\u5bb9\u6027 <\/h4>\n<p> \u4e0d\u540c\u7684SAPI\u53ef\u80fd\u5bf9\u7279\u5b9a\u7684\u5e94\u7528\u6846\u67b6\u652f\u6301\u7a0b\u5ea6\u4e0d\u540c\u3002\u4f8b\u5982&#xff0c;Laravel\u6846\u67b6\u63d0\u4f9b\u4e86\u5bf9php-fpm\u7684\u4f18\u5316\u652f\u6301&#xff0c;\u4f7f\u5f97\u5728\u9ad8\u6d41\u91cf\u73af\u5883\u4e0b\u83b7\u5f97\u66f4\u4f73\u7684\u6027\u80fd\u3002\u8fd9\u9700\u8981\u5f00\u53d1\u8005\u5728\u6846\u67b6\u548cSAPI\u9009\u62e9\u65f6\u8fdb\u884c\u6743\u8861\u3002 <\/p>\n<h3> 5.3 \u5b89\u5168\u6027\u4e0e\u7ef4\u62a4\u6027\u8003\u91cf <\/h3>\n<p> \u5b89\u5168\u6027\u662f\u9009\u62e9SAPI\u65f6\u4e0d\u53ef\u6216\u7f3a\u7684\u8003\u8651\u70b9\u3002 <\/p>\n<h4> 5.3.1 \u4e0d\u540cSAPI\u7684\u5b89\u5168\u98ce\u9669\u8bc4\u4f30 <\/h4>\n<p> \u4e0d\u540c\u7684SAPI\u5b9e\u73b0\u6709\u4e0d\u540c\u7684\u5b89\u5168\u98ce\u9669\u3002\u6bd4\u5982&#xff0c;\u4f7f\u7528CLI SAPI\u65f6&#xff0c;\u56e0\u4e3a\u5176\u5728\u547d\u4ee4\u884c\u73af\u5883\u4e0b\u8fd0\u884c&#xff0c;\u53ef\u80fd\u4e0d\u4f1a\u50cfphp-fpm\u90a3\u6837\u63d0\u4f9b\u72ec\u7acb\u7528\u6237\u5904\u7406&#xff0c;\u56e0\u6b64\u5728\u5b89\u5168\u6027\u65b9\u9762\u9700\u8981\u66f4\u591a\u7684\u8003\u91cf\u548c\u914d\u7f6e\u3002 <\/p>\n<h4> 5.3.2 \u957f\u671f\u7ef4\u62a4\u4e0e\u5347\u7ea7\u7684SAPI\u7b56\u7565 <\/h4>\n<p> \u9009\u62e9\u4e00\u4e2a\u62e5\u6709\u6d3b\u8dc3\u793e\u533a\u548c\u826f\u597d\u7ef4\u62a4\u8bb0\u5f55\u7684SAPI\u540c\u6837\u91cd\u8981\u3002\u5728\u9762\u4e34\u9700\u8981\u5347\u7ea7\u6216\u8865\u4e01\u4fee\u590d\u65f6&#xff0c;\u4e00\u4e2a\u6d3b\u8dc3\u7684\u793e\u533a\u80fd\u591f\u63d0\u4f9b\u5feb\u901f\u7684\u652f\u6301\u548c\u89e3\u51b3\u65b9\u6848\u3002 <\/p>\n<p> \u5728\u603b\u7ed3\u672c\u7ae0\u8282\u5185\u5bb9\u65f6&#xff0c;\u8bf7\u6ce8\u610f&#xff0c;\u9009\u62e9\u5408\u9002\u7684SAPI\u5bf9\u4e8e\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3001\u5b89\u5168\u6027\u548c\u7ef4\u62a4\u6027\u81f3\u5173\u91cd\u8981\u3002\u8fd9\u9700\u8981\u5f00\u53d1\u8005\u5728\u4e86\u89e3\u4e0d\u540cSAPI\u7684\u4f18\u52bf\u548c\u9650\u5236\u7684\u57fa\u7840\u4e0a&#xff0c;\u6839\u636e\u5b9e\u9645\u90e8\u7f72\u73af\u5883\u3001\u5e94\u7528\u9700\u6c42\u4ee5\u53ca\u5b89\u5168\u548c\u7ef4\u62a4\u7b56\u7565&#xff0c;\u505a\u51fa\u660e\u667a\u7684\u9009\u62e9\u3002 <\/p>\n<p> \u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d&#xff0c;\u9009\u62e9SAPI\u7c7b\u578b\u540e&#xff0c;\u901a\u5e38\u9700\u8981\u914d\u7f6eWeb\u670d\u52a1\u5668\u548cPHP\u73af\u5883\u6765\u5b9e\u73b0\u6700\u4f73\u6027\u80fd\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684php-fpm\u914d\u7f6e\u793a\u4f8b&#xff0c;\u7528\u4e8e\u5c55\u793a\u5982\u4f55\u5728Nginx\u670d\u52a1\u5668\u4e2d\u8fdb\u884c\u914d\u7f6e&#xff1a; <\/p>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name example.com;<\/p>\n<p>    root \/var\/www\/html;<br \/>\n    index index.php index.html index.htm;<\/p>\n<p>    location ~ \\\\.php$ {<br \/>\n        try_files $uri &#061;404;<br \/>\n        fastcgi_pass unix:\/var\/run\/php\/php7.4-fpm.sock;<br \/>\n        fastcgi_index index.php;<br \/>\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>\n        include fastcgi_params;<br \/>\n    }<br \/>\n}<\/p>\n<p> \u5728\u8be5\u914d\u7f6e\u4e2d&#xff0c;\u5b9a\u4e49\u4e86\u4e00\u4e2a\u76d1\u542c80\u7aef\u53e3\u7684Nginx\u670d\u52a1\u5668&#xff0c;\u5c06\u8bf7\u6c42\u4e2d\u4ee5  .php  \u7ed3\u5c3e\u7684\u6587\u4ef6\u901a\u8fc7Unix\u5957\u63a5\u5b57\u4f20\u9012\u7ed9php-fpm\u8fdb\u884c\u5904\u7406\u3002 <\/p>\n<p> \u6b64\u5916&#xff0c;\u4e3a\u4e86\u786e\u4fddSAPI\u7684\u5b89\u5168\u6027&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u5982  phpinfo()  \u51fd\u6570\u8fdb\u884c\u68c0\u67e5&#xff0c;\u4ee5\u786e\u4fdd\u6b63\u786e\u7684\u914d\u7f6e&#xff0c;\u4ee5\u53ca\u9075\u5faa\u6700\u4f73\u5b9e\u8df5&#xff0c;\u4f8b\u5982\u914d\u7f6e\u6587\u4ef6\u7684\u6743\u9650\u8bbe\u7f6e\u7b49\u3002 <\/p>\n<p>  \u672c\u6587\u8fd8\u6709\u914d\u5957\u7684\u7cbe\u54c1\u8d44\u6e90&#xff0c;\u70b9\u51fb\u83b7\u53d6  <img decoding=\"async\" alt=\"menu-r.4af5f7ec.gif\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201153-68892b095f84c.gif\" style=\"width:16px;margin-left:4px;vertical-align:text-bottom;cursor:text\" \/> <\/p>\n<p> \u7b80\u4ecb&#xff1a;\u201c\u4ea7\u54c1_sapi\u201d\u53ef\u80fd\u6307\u4e00\u4e2a\u4e0eServer Application Programming Interface&#xff08;SAPI&#xff09;\u7ed3\u5408\u7684\u7279\u5b9a\u4ea7\u54c1\u3002SAPI\u662fPHP\u4e2d\u7684\u5173\u952e\u6982\u5ff5&#xff0c;\u5b83\u6807\u51c6\u5316\u4e86PHP\u4e0eWeb\u670d\u52a1\u5668\u7684\u4ea4\u4e92\u65b9\u5f0f\u3002\u672c\u6587\u63a2\u8ba8\u4e86SAPI\u7684\u57fa\u672c\u6982\u5ff5\u3001PHP\u4e0eSAPI\u7684\u5173\u7cfb\u3001SAPI\u7684\u4f5c\u7528\u3001\u5e38\u89c1\u7684SAPI\u793a\u4f8b&#xff0c;\u4ee5\u53ca\u5728\u9009\u62e9SAPI\u65f6\u7684\u8003\u8651\u56e0\u7d20\u3002\u6b64\u5916&#xff0c;\u672c\u6587\u5bf9\u201c\u4ea7\u54c1_sapi\u201d\u7684\u53ef\u80fd\u542b\u4e49\u8fdb\u884c\u4e86\u8ba8\u8bba&#xff0c;\u6307\u51fa\u5b83\u53ef\u80fd\u662f\u4e00\u4e2a\u7279\u5b9a\u4ea7\u54c1\u6216\u670d\u52a1\u7684SAPI\u5b9e\u73b0&#xff0c;\u65e8\u5728\u63d0\u4f9b\u6027\u80fd\u4f18\u5316\u3001\u589e\u5f3a\u5b89\u5168\u6216\u7279\u5b9a\u96c6\u6210\u9700\u6c42\u3002 <\/p>\n<p>   \u672c\u6587\u8fd8\u6709\u914d\u5957\u7684\u7cbe\u54c1\u8d44\u6e90&#xff0c;\u70b9\u51fb\u83b7\u53d6   <img decoding=\"async\" alt=\"menu-r.4af5f7ec.gif\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201153-68892b095f84c.gif\" style=\"width:16px;margin-left:4px;vertical-align:text-bottom;cursor:text\" \/>  <\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb986\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf26\u6b21\u3002\u670d\u52a1\u5668API\uff08Server Application Programming Interface\uff0c\u7b80\u79f0SAPI\uff09\u662fPHP\u7684\u4e00\u4e2a\u62bd\u8c61\u5c42\uff0c\u5b83\u5b9a\u4e49\u4e86PHP\u5982\u4f55\u4e0eWeb\u670d\u52a1\u5668\u6216\u5176\u4ed6CGI\u5c01\u88c5\u5668\u4ea4\u4e92\u3002SAPI\u4f7f\u5f97PHP\u80fd\u591f\u72ec\u7acb\u4e8e\u4e0d\u540c\u7684\u670d\u52a1\u5668\u73af\u5883\u8fd0\u884c\uff0c\u65e0\u8bba\u662f\u547d\u4ee4\u884c\u754c\u9762\uff08CLI\uff09\u3001Apache\u6a21\u5757\u3001Nginx\u6a21\u5757\u8fd8\u662f\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684CGI\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"author":2,"featured_media":46800,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-46802","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/46802.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb986\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf26\u6b21\u3002\u670d\u52a1\u5668API\uff08Server Application Programming Interface\uff0c\u7b80\u79f0SAPI\uff09\u662fPHP\u7684\u4e00\u4e2a\u62bd\u8c61\u5c42\uff0c\u5b83\u5b9a\u4e49\u4e86PHP\u5982\u4f55\u4e0eWeb\u670d\u52a1\u5668\u6216\u5176\u4ed6CGI\u5c01\u88c5\u5668\u4ea4\u4e92\u3002SAPI\u4f7f\u5f97PHP\u80fd\u591f\u72ec\u7acb\u4e8e\u4e0d\u540c\u7684\u670d\u52a1\u5668\u73af\u5883\u8fd0\u884c\uff0c\u65e0\u8bba\u662f\u547d\u4ee4\u884c\u754c\u9762\uff08CLI\uff09\u3001Apache\u6a21\u5757\u3001Nginx\u6a21\u5757\u8fd8\u662f\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684CGI\u7a0b\u5e8f\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46802.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T20:11:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201153-68892b095f84c.gif\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46802.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46802.html\",\"name\":\"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T20:11:54+00:00\",\"dateModified\":\"2025-07-29T20:11:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46802.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46802.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46802.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/46802.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb986\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf26\u6b21\u3002\u670d\u52a1\u5668API\uff08Server Application Programming Interface\uff0c\u7b80\u79f0SAPI\uff09\u662fPHP\u7684\u4e00\u4e2a\u62bd\u8c61\u5c42\uff0c\u5b83\u5b9a\u4e49\u4e86PHP\u5982\u4f55\u4e0eWeb\u670d\u52a1\u5668\u6216\u5176\u4ed6CGI\u5c01\u88c5\u5668\u4ea4\u4e92\u3002SAPI\u4f7f\u5f97PHP\u80fd\u591f\u72ec\u7acb\u4e8e\u4e0d\u540c\u7684\u670d\u52a1\u5668\u73af\u5883\u8fd0\u884c\uff0c\u65e0\u8bba\u662f\u547d\u4ee4\u884c\u754c\u9762\uff08CLI\uff09\u3001Apache\u6a21\u5757\u3001Nginx\u6a21\u5757\u8fd8\u662f\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684CGI\u7a0b\u5e8f\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/46802.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T20:11:54+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201153-68892b095f84c.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46802.html","url":"https:\/\/www.wsisp.com\/helps\/46802.html","name":"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T20:11:54+00:00","dateModified":"2025-07-29T20:11:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46802.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46802.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46802.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4ea7\u54c1SAPI\uff1a\u670d\u52a1\u5668\u63a5\u53e3\u7f16\u7a0b\u4e0ePHP\u96c6\u6210"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=46802"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46802\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/46800"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46802"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}