{"id":48020,"date":"2024-12-02T12:52:16","date_gmt":"2024-12-02T04:52:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48020\/"},"modified":"2024-12-02T12:52:16","modified_gmt":"2024-12-02T04:52:16","slug":"php-%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84%e9%85%8d%e7%bd%ae%e5%a6%82%e4%bd%95%e5%bd%b1%e5%93%8d%e5%87%bd%e6%95%b0%e6%80%a7%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48020\/","title":{"rendered":"PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300aPHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p>PHP \u865a\u62df\u673a (VM) \u7684\u914d\u7f6e\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1a\u5185\u5b58\u9650\u5236 (memory_limit)\uff1a\u8bbe\u7f6e PHP \u6267\u884c\u51fd\u6570\u7684\u53ef\u7528\u5185\u5b58\u91cf\uff0c\u8fc7\u4f4e\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u4e0d\u8db3\u9519\u8bef\u3002\u6700\u5927\u6267\u884c\u65f6\u95f4 (max_execution_time)\uff1a\u9650\u5236 PHP \u51fd\u6570\u7684\u6267\u884c\u65f6\u957f\uff0c\u592a\u4f4e\u53ef\u80fd\u5bfc\u81f4\u51fd\u6570\u8d85\u65f6\u3002OPcache \u542f\u7528 (opcache.enable)\uff1a\u542f\u7528\u540e\uff0c\u53ef\u7f13\u5b58\u5df2\u7f16\u8bd1\u7684 PHP \u4ee3\u7801\uff0c\u63d0\u5347\u6267\u884c\u901f\u5ea6\u3002OPcache \u5927\u5c0f (opcache.memory_consumption)\uff1a\u5206\u914d\u7ed9 OPcache \u7684\u5185\u5b58\u91cf\uff0c\u589e\u52a0\u53ef\u5206\u914d\u66f4\u591a\u5185\u5b58\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729949324671cee8c39f7c.jpg\" class=\"aligncenter\" title=\"PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f\u63d2\u56fe\" alt=\"PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f<\/strong><\/p>\n<p>PHP \u865a\u62df\u673a (VM) \u662f\u4e00\u4e2a\u8d1f\u8d23\u6267\u884c PHP \u4ee3\u7801\u7684\u8f6f\u4ef6\u5c42\u3002\u5b83\u7684\u914d\u7f6e\u53ef\u4ee5\u6781\u5927\u5730\u5f71\u54cd\u51fd\u6570\u6267\u884c\u7684\u6027\u80fd\u3002\u4e86\u89e3 VM \u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\u5bf9\u4e8e\u4f18\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>\u5f71\u54cd\u56e0\u7d20<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u5f71\u54cd PHP \u51fd\u6570\u6027\u80fd\u7684\u5173\u952e VM \u914d\u7f6e\u8bbe\u7f6e\uff1a<\/p>\n<ul>\n<li><strong>\u5185\u5b58\u9650\u5236 (memory_limit)<\/strong>\uff1a\u9650\u5236 PHP \u53ef\u7528\u4e8e\u6267\u884c\u51fd\u6570\u7684\u5185\u5b58\u91cf\u3002<\/li>\n<li><strong>\u6700\u5927\u6267\u884c\u65f6\u95f4 (max_execution_time)<\/strong>\uff1a\u9650\u5236 PHP \u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u3002<\/li>\n<li><strong>OPcache \u542f\u7528 (opcache.enable)<\/strong>\uff1a\u542f\u7528 OPcache\uff0c\u4e00\u79cd\u7f13\u5b58\u5df2\u7f16\u8bd1\u7684 PHP \u4ee3\u7801\u4ee5\u63d0\u9ad8\u6267\u884c\u901f\u5ea6\u3002<\/li>\n<li><strong>OPcache \u5927\u5c0f (opcache.memory_consumption)<\/strong>\uff1a\u5206\u914d\u7ed9 OPcache \u7684\u5185\u5b58\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6848\u4f8b 1\uff1a\u5185\u5b58\u9650\u5236<\/strong><\/p>\n<pre>function large_array() {\n    return range(0, 100000);\n}<\/pre>\n<p>\u6b64\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 100,000 \u7684\u6570\u7ec4\u3002\u5982\u679c PHP \u7684 <code>memory_limit<\/code> \u8bbe\u7f6e\u8fc7\u4f4e\uff0c\u5728\u6267\u884c\u6b64\u51fd\u6570\u65f6\u53ef\u80fd\u4f1a\u51fa\u73b0 &#8220;\u5185\u5b58\u4e0d\u8db3&#8221; \u9519\u8bef\u3002<\/p>\n<p><strong>\u6848\u4f8b 2\uff1a\u6700\u5927\u6267\u884c\u65f6\u95f4<\/strong><\/p>\n<pre>function long_loop() {\n    for ($i = 0; $i &lt; 1000000; $i++) {\n        \/\/ ...\n    }\n}<\/pre>\n<p>\u6b64\u51fd\u6570\u6267\u884c\u4e00\u4e2a\u957f\u5ea6\u4e3a 1,000,000 \u7684\u5faa\u73af\u3002\u5982\u679c <code>max_execution_time<\/code> \u8bbe\u7f6e\u592a\u4f4e\uff0c\u6b64\u51fd\u6570\u53ef\u80fd\u4f1a\u5728\u5b8c\u6210\u6267\u884c\u4e4b\u524d\u8d85\u65f6\u3002<\/p>\n<p><strong>\u6848\u4f8b 3\uff1aOPcache<\/strong><\/p>\n<pre>\/\/ OPCache \u5df2\u542f\u7528\nfunction opcached_function() {\n    \/\/ ...\n}<\/pre>\n<p>\u6b64\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528 OPcache\uff0c\u56e0\u4e3a\u5b83\u5df2\u542f\u7528\u3002\u5c06\u7ecf\u5e38\u6267\u884c\u7684\u51fd\u6570\u653e\u5165\u7f13\u5b58\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u5176\u6027\u80fd\u3002<\/p>\n<p><strong>\u4f18\u5316\u5efa\u8bae<\/strong><\/p>\n<ul>\n<li>\u8c03\u6574 <code>memory_limit<\/code> \u4ee5\u907f\u514d\u5185\u5b58\u95ee\u9898\u3002<\/li>\n<li>\u8c03\u6574 <code>max_execution_time<\/code> \u4ee5\u907f\u514d\u8d85\u65f6\u3002<\/li>\n<li>\u542f\u7528 OPcache \u4ee5\u7f13\u5b58\u7ecf\u5e38\u6267\u884c\u7684\u4ee3\u7801\u3002<\/li>\n<li>\u589e\u52a0 <code>opcache.memory_consumption<\/code> \u4ee5\u4e3a OPcache \u5206\u914d\u66f4\u591a\u5185\u5b58\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u4ed4\u7ec6\u914d\u7f6e PHP VM \u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u51fd\u6570\u6027\u80fd\u3002\u901a\u8fc7\u8c03\u6574\u5185\u5b58\u9650\u5236\u3001\u6700\u5927\u6267\u884c\u65f6\u95f4\u548c OPcache \u914d\u7f6e\uff0c\u53ef\u4ee5\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\u5e76\u4f7f\u5176\u66f4\u6709\u6548\u7387\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ephp,\u51fd\u6570\u6027\u80fd\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f \u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300aPHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002 PHP \u865a\u62df\u673a (VM) \u7684\u914d\u7f6e\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1a\u5185\u5b58\u9650\u5236 (memory_limit)\uff1a\u8bbe\u7f6e PHP \u6267\u884c\u51fd\u6570\u7684\u53ef\u7528\u5185\u5b58\u91cf\uff0c\u8fc7\u4f4e\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u4e0d\u8db3\u9519\u8bef\u3002\u6700\u5927\u6267\u884c\u65f6\u95f4 (max_execution_time)\uff1a\u9650\u5236 PHP \u51fd\u6570\u7684\u6267\u884c\u65f6\u957f\uff0c\u592a\u4f4e\u53ef\u80fd\u5bfc\u81f4\u51fd\u6570\u8d85\u65f6\u3002OPcache \u542f\u7528 (opcache.enable)\uff1a\u542f\u7528\u540e\uff0c\u53ef\u7f13\u5b58\u5df2\u7f16\u8bd1\u7684 PHP \u4ee3\u7801\uff0c\u63d0\u5347\u6267\u884c\u901f\u5ea6\u3002OPcache \u5927\u5c0f (opcache.memory_consumption)\uff1a\u5206\u914d\u7ed9 OPcache \u7684\u5185\u5b58\u91cf\uff0c\u589e\u52a0\u53ef\u5206\u914d\u66f4\u591a\u5185\u5b58\u3002 PHP \u865a\u62df\u673a\u7684\u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\uff1f PHP \u865a\u62df\u673a (VM) \u662f\u4e00\u4e2a\u8d1f\u8d23\u6267\u884c PHP \u4ee3\u7801\u7684\u8f6f\u4ef6\u5c42\u3002\u5b83\u7684\u914d\u7f6e\u53ef\u4ee5\u6781\u5927\u5730\u5f71\u54cd\u51fd\u6570\u6267\u884c\u7684\u6027\u80fd\u3002\u4e86\u89e3 VM \u914d\u7f6e\u5982\u4f55\u5f71\u54cd\u51fd\u6570\u6027\u80fd\u5bf9\u4e8e\u4f18\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\u3002 \u5f71\u54cd\u56e0\u7d20 \u4ee5\u4e0b\u662f\u5f71\u54cd PHP \u51fd\u6570\u6027\u80fd\u7684\u5173\u952e VM \u914d\u7f6e\u8bbe\u7f6e\uff1a \u5185\u5b58\u9650\u5236 (memory_limit)\uff1a\u9650\u5236 PHP \u53ef\u7528\u4e8e\u6267\u884c\u51fd\u6570\u7684\u5185\u5b58\u91cf\u3002 \u6700\u5927\u6267\u884c\u65f6\u95f4 (max_execution_time)\uff1a\u9650\u5236 PHP \u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u3002 OPcache \u542f\u7528 (opcache.enable)\uff1a\u542f\u7528 OPcache\uff0c\u4e00\u79cd\u7f13\u5b58\u5df2\u7f16\u8bd1\u7684 PHP \u4ee3\u7801\u4ee5\u63d0\u9ad8\u6267\u884c\u901f\u5ea6\u3002 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-48020","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48020","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=48020"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48020\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}