{"id":47266,"date":"2024-12-02T10:48:46","date_gmt":"2024-12-02T02:48:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47266\/"},"modified":"2024-12-02T10:48:46","modified_gmt":"2024-12-02T02:48:46","slug":"php%e5%87%bd%e6%95%b0%e7%bc%93%e5%ad%98%e6%8a%80%e6%9c%af%e7%9a%84%e6%8c%91%e6%88%98%e4%b8%8e%e6%9c%ba%e9%81%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47266\/","title":{"rendered":"PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u901a\u8fc7\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u7f16\u8bd1\u540e\u7684\u51fd\u6570\u4ee3\u7801\u6765\u52a0\u901f PHP \u5e94\u7528\u7a0b\u5e8f\uff0c\u5e26\u6765\u6027\u80fd\u63d0\u5347\u3001\u53ef\u4f38\u7f29\u6027\u548c\u8d44\u6e90\u4f18\u5316\u3002\u7136\u800c\uff0c\u5b83\u4e5f\u9762\u4e34\u7740\u5185\u5b58\u5f00\u9500\u3001\u7ef4\u62a4\u548c\u517c\u5bb9\u6027\u6311\u6218\u3002\u514b\u670d\u8fd9\u4e9b\u6311\u6218\u540e\uff0c\u51fd\u6570\u7f13\u5b58\u6210\u4e3a\u63d0\u9ad8 PHP \u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u7684\u6709\u529b\u5de5\u5177\uff0c\u5982\u4f7f\u7528 OPcache \u6269\u5c55\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729907916671c4ccce0044.jpg\" class=\"aligncenter\" title=\"PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047\u63d2\u56fe\" alt=\"PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u662f\u4e00\u79cd\u7528\u4e8e\u52a0\u901f PHP \u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\uff0c\u5b83\u901a\u8fc7\u5c06\u7f16\u8bd1\u540e\u7684\u51fd\u6570\u4ee3\u7801\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u6765\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u7684\u5f00\u9500\u3002\u5728\u9ad8\u6d41\u91cf\u7f51\u7ad9\u4e0a\uff0c\u8fd9\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<p><strong>\u6311\u6218<\/strong><\/p>\n<p>\u5c3d\u7ba1\u51fd\u6570\u7f13\u5b58\u63d0\u4f9b\u4e86\u663e\u7740\u7684\u597d\u5904\uff0c\u4f46\u5b83\u4e5f\u5e26\u6765\u4e86\u4e00\u4e9b\u6311\u6218\uff1a<\/p>\n<ul>\n<li><strong>\u5185\u5b58\u5f00\u9500\uff1a<\/strong> \u7f13\u5b58\u51fd\u6570\u9700\u8981\u5360\u7528\u989d\u5916\u7684\u5185\u5b58\uff0c\u8fd9\u53ef\u80fd\u5bf9\u8f83\u5927\u7684\u5e94\u7528\u7a0b\u5e8f\u6784\u6210\u95ee\u9898\u3002<\/li>\n<li><strong>\u7ef4\u62a4\u95ee\u9898\uff1a<\/strong> \u5f53\u51fd\u6570\u4ee3\u7801\u66f4\u6539\u65f6\uff0c\u7f13\u5b58\u5fc5\u987b\u66f4\u65b0\uff0c\u8fd9\u53ef\u80fd\u662f\u4e00\u4e2a\u590d\u6742\u4e14\u5bb9\u6613\u51fa\u9519\u7684\u8fc7\u7a0b\u3002<\/li>\n<li><strong>\u517c\u5bb9\u6027\uff1a<\/strong> \u5e76\u975e\u6240\u6709 PHP \u51fd\u6570\u90fd\u53ef\u7f13\u5b58\uff0c\u56e0\u6b64\u5728\u5b9e\u65bd\u7f13\u5b58\u673a\u5236\u65f6\u9700\u8981\u5c0f\u5fc3\u3002<\/li>\n<\/ul>\n<p><strong>\u673a\u9047<\/strong><\/p>\n<p>\u514b\u670d\u8fd9\u4e9b\u6311\u6218\u540e\uff0c\u51fd\u6570\u7f13\u5b58\u53ef\u4ee5\u4e3a PHP \u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4ee5\u4e0b\u673a\u9047\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong> \u51fd\u6570\u8c03\u7528\u901f\u5ea6\u66f4\u5feb\uff0c\u51cf\u5c11\u4e86\u5e94\u7528\u7a0b\u5e8f\u54cd\u5e94\u65f6\u95f4\u3002<\/li>\n<li><strong>\u53ef\u4f38\u7f29\u6027\uff1a<\/strong> \u80fd\u591f\u5904\u7406\u66f4\u9ad8\u7684\u6d41\u91cf\uff0c\u800c\u4e0d\u4f1a\u5bf9\u6027\u80fd\u4ea7\u751f\u91cd\u5927\u5f71\u54cd\u3002<\/li>\n<li><strong>\u8d44\u6e90\u4f18\u5316\uff1a<\/strong> \u901a\u8fc7\u51cf\u5c11\u670d\u52a1\u5668\u8d1f\u8f7d\uff0c\u53ef\u4ee5\u4f18\u5316\u5176\u4ed6\u8d44\u6e90\uff0c\u4f8b\u5982 CPU \u548c\u5185\u5b58\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8ba9\u6211\u4eec\u4f7f\u7528\u6d41\u884c\u7684 PHP \u7f13\u5b58\u6269\u5c55 OPcache \u6765\u6f14\u793a\u51fd\u6570\u7f13\u5b58\u3002<\/p>\n<p><strong>\u5b89\u88c5 OPcache<\/strong><\/p>\n<pre>sudo apt install php-opcache # Ubuntu\/Debian\nsudo yum install php-opcache # CentOS\/Red Hat<\/pre>\n<p><strong>\u542f\u7528 OPcache<\/strong><\/p>\n<p>\u5728 php.ini \u4e2d\u542f\u7528 OPcache\uff1a<\/p>\n<pre>; Enable opcode caching\nopcache.enable=1<\/pre>\n<p><strong>\u914d\u7f6e OPcache<\/strong><\/p>\n<p>\u4f18\u5316 OPcache \u8bbe\u7f6e\u4ee5\u6ee1\u8db3\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u6c42\uff1a<\/p>\n<pre>; Memory usage limit\nopcache.memory_consumption=128\n; Expiration time for cached files\nopcache.revalidate_freq=0<\/pre>\n<p><strong>\u9a8c\u8bc1\u7f13\u5b58<\/strong><\/p>\n<p>\u4f7f\u7528 <code>cache:info<\/code> CLI \u547d\u4ee4\u9a8c\u8bc1\u7f13\u5b58\u72b6\u6001\uff1a<\/p>\n<pre>php -r \"var_dump(opcache_get_status());\"<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u662f\u63d0\u9ad8 PHP \u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u7684\u6709\u6548\u6280\u672f\u3002\u901a\u8fc7\u7ba1\u7406\u6311\u6218\u5e76\u5145\u5206\u5229\u7528\u673a\u9047\uff0c\u60a8\u53ef\u4ee5\u663e\u7740\u63d0\u5347\u7f51\u7ad9\u901f\u5ea6\u548c\u53ef\u4f38\u7f29\u6027\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ephp,\u7f13\u5b58\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047 \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300aPHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047\u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 \u51fd\u6570\u7f13\u5b58\u6280\u672f\u901a\u8fc7\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u7f16\u8bd1\u540e\u7684\u51fd\u6570\u4ee3\u7801\u6765\u52a0\u901f PHP \u5e94\u7528\u7a0b\u5e8f\uff0c\u5e26\u6765\u6027\u80fd\u63d0\u5347\u3001\u53ef\u4f38\u7f29\u6027\u548c\u8d44\u6e90\u4f18\u5316\u3002\u7136\u800c\uff0c\u5b83\u4e5f\u9762\u4e34\u7740\u5185\u5b58\u5f00\u9500\u3001\u7ef4\u62a4\u548c\u517c\u5bb9\u6027\u6311\u6218\u3002\u514b\u670d\u8fd9\u4e9b\u6311\u6218\u540e\uff0c\u51fd\u6570\u7f13\u5b58\u6210\u4e3a\u63d0\u9ad8 PHP \u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u7684\u6709\u529b\u5de5\u5177\uff0c\u5982\u4f7f\u7528 OPcache \u6269\u5c55\u6240\u793a\u3002 PHP \u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u6311\u6218\u4e0e\u673a\u9047 \u7b80\u4ecb \u51fd\u6570\u7f13\u5b58\u6280\u672f\u662f\u4e00\u79cd\u7528\u4e8e\u52a0\u901f PHP \u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\uff0c\u5b83\u901a\u8fc7\u5c06\u7f16\u8bd1\u540e\u7684\u51fd\u6570\u4ee3\u7801\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u6765\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u7684\u5f00\u9500\u3002\u5728\u9ad8\u6d41\u91cf\u7f51\u7ad9\u4e0a\uff0c\u8fd9\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u6027\u80fd\u3002 \u6311\u6218 \u5c3d\u7ba1\u51fd\u6570\u7f13\u5b58\u63d0\u4f9b\u4e86\u663e\u7740\u7684\u597d\u5904\uff0c\u4f46\u5b83\u4e5f\u5e26\u6765\u4e86\u4e00\u4e9b\u6311\u6218\uff1a \u5185\u5b58\u5f00\u9500\uff1a \u7f13\u5b58\u51fd\u6570\u9700\u8981\u5360\u7528\u989d\u5916\u7684\u5185\u5b58\uff0c\u8fd9\u53ef\u80fd\u5bf9\u8f83\u5927\u7684\u5e94\u7528\u7a0b\u5e8f\u6784\u6210\u95ee\u9898\u3002 \u7ef4\u62a4\u95ee\u9898\uff1a \u5f53\u51fd\u6570\u4ee3\u7801\u66f4\u6539\u65f6\uff0c\u7f13\u5b58\u5fc5\u987b\u66f4\u65b0\uff0c\u8fd9\u53ef\u80fd\u662f\u4e00\u4e2a\u590d\u6742\u4e14\u5bb9\u6613\u51fa\u9519\u7684\u8fc7\u7a0b\u3002 \u517c\u5bb9\u6027\uff1a \u5e76\u975e\u6240\u6709 PHP \u51fd\u6570\u90fd\u53ef\u7f13\u5b58\uff0c\u56e0\u6b64\u5728\u5b9e\u65bd\u7f13\u5b58\u673a\u5236\u65f6\u9700\u8981\u5c0f\u5fc3\u3002 \u673a\u9047 \u514b\u670d\u8fd9\u4e9b\u6311\u6218\u540e\uff0c\u51fd\u6570\u7f13\u5b58\u53ef\u4ee5\u4e3a PHP \u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4ee5\u4e0b\u673a\u9047\uff1a \u6027\u80fd\u63d0\u5347\uff1a \u51fd\u6570\u8c03\u7528\u901f\u5ea6\u66f4\u5feb\uff0c\u51cf\u5c11\u4e86\u5e94\u7528\u7a0b\u5e8f\u54cd\u5e94\u65f6\u95f4\u3002 \u53ef\u4f38\u7f29\u6027\uff1a \u80fd\u591f\u5904\u7406\u66f4\u9ad8\u7684\u6d41\u91cf\uff0c\u800c\u4e0d\u4f1a\u5bf9\u6027\u80fd\u4ea7\u751f\u91cd\u5927\u5f71\u54cd\u3002 \u8d44\u6e90\u4f18\u5316\uff1a \u901a\u8fc7\u51cf\u5c11\u670d\u52a1\u5668\u8d1f\u8f7d\uff0c\u53ef\u4ee5\u4f18\u5316\u5176\u4ed6\u8d44\u6e90\uff0c\u4f8b\u5982 CPU \u548c\u5185\u5b58\u3002 \u5b9e\u6218\u6848\u4f8b \u8ba9\u6211\u4eec\u4f7f\u7528\u6d41\u884c\u7684 PHP \u7f13\u5b58\u6269\u5c55 OPcache \u6765\u6f14\u793a\u51fd\u6570\u7f13\u5b58\u3002 \u5b89\u88c5 OPcache sudo apt install php-opcache # Ubuntu\/Debian sudo yum install php-opcache [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47266","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47266"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47266\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}