{"id":48368,"date":"2024-12-02T16:48:40","date_gmt":"2024-12-02T08:48:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48368\/"},"modified":"2024-12-02T16:48:40","modified_gmt":"2024-12-02T08:48:40","slug":"php%e5%87%bd%e6%95%b0%e7%bc%93%e5%ad%98%e7%9a%84%e9%85%8d%e7%bd%ae%e4%b8%8e%e7%ae%a1%e7%90%86%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48368\/","title":{"rendered":"PHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p>PHP \u51fd\u6570\u7f13\u5b58\u53ef\u901a\u8fc7 php.ini \u914d\u7f6e\uff08opcache.enable \u548c opcache.memory_consumption\uff09\uff0c\u5e76\u53ef\u901a\u8fc7\u68c0\u67e5 phpinfo() \u548c\u4f7f\u7528 opcache_reset() \u51fd\u6570\u6765\u7ba1\u7406\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c\u901a\u8fc7\u542f\u7528\u51fd\u6570\u7f13\u5b58\u5e76\u9002\u5f53\u8bbe\u7f6e WooCommerce \u5546\u5e97\u7684\u5185\u5b58\u6d88\u8017\u91cf\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5176\u901f\u5ea6\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730018679671dfd77483f9.jpg\" class=\"aligncenter\" title=\"PHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3\u63d2\u56fe\" alt=\"PHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u7f13\u5b58\u914d\u7f6e\u548c\u7ba1\u7406<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u51fd\u6570\u7f13\u5b58\uff08opcode cache\uff09\u7528\u4e8e\u5b58\u50a8\u5df2\u7f16\u8bd1\u7684 PHP \u51fd\u6570\uff0c\u4ece\u800c\u52a0\u5feb\u811a\u672c\u6267\u884c\u901f\u5ea6\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd PHP \u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5b9e\u6218\u6848\u4f8b\u3002<\/p>\n<p><strong>\u914d\u7f6e<\/strong><\/p>\n<p>\u5728 php.ini \u4e2d\u627e\u5230\u4ee5\u4e0b\u8bbe\u7f6e\uff1a<\/p>\n<pre>opcache.enable = 1\nopcache.memory_consumption = 128<\/pre>\n<ul>\n<li><code>opcache.enable<\/code>\uff1a\u542f\u7528\u6216\u7981\u7528\u51fd\u6570\u7f13\u5b58\uff0c\u8bbe\u7f6e\u4e3a 1 \u4ee5\u542f\u7528\u3002<\/li>\n<li><code>opcache.memory_consumption<\/code>\uff1a\u6307\u5b9a\u51fd\u6570\u7f13\u5b58\u7684\u5185\u5b58\u5360\u7528\u5927\u5c0f\uff08\u4ee5\u5146\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\u3002\u6839\u636e\u7cfb\u7edf\u4e2d\u7684\u53ef\u7528\u5185\u5b58\u548c\u5904\u7406\u7684\u811a\u672c\u6570\u91cf\u8fdb\u884c\u8c03\u6574\u3002<\/li>\n<\/ul>\n<p><strong>\u7ba1\u7406<\/strong><\/p>\n<p><strong>\u68c0\u67e5\u72b6\u6001<\/strong><\/p>\n<pre>phpinfo();<\/pre>\n<p>\u8f93\u51fa\u4e2d\u67e5\u627e <code>opcache<\/code> \u90e8\u5206\uff0c\u68c0\u67e5\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li><code>opcache.enabled<\/code>\uff1a\u663e\u793a\u7f13\u5b58\u662f\u5426\u5df2\u542f\u7528\u3002<\/li>\n<li><code>opcache.memory_consumption<\/code>\uff1a\u663e\u793a\u7f13\u5b58\u7684\u5185\u5b58\u5360\u7528\u91cf\u3002<\/li>\n<li><code>opcache.statistics<\/code>\uff1a\u63d0\u4f9b\u6709\u5173\u7f13\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u8be6\u7ec6\u7edf\u8ba1\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><strong>\u6e05\u9664\u7f13\u5b58<\/strong><\/p>\n<pre>opcache_reset();<\/pre>\n<p>\u5982\u679c\u505a\u4e86\u4ee3\u7801\u66f4\u6539\u6216\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b64\u51fd\u6570\u6e05\u9664\u7f13\u5b58\u5e76\u91cd\u65b0\u7f16\u8bd1\u51fd\u6570\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u4f18\u5316 WooCommerce<\/strong><\/p>\n<p>WooCommerce \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u7535\u5b50\u5546\u52a1\u63d2\u4ef6\uff0c\u4ee5\u5176\u5e9e\u5927\u4e14\u590d\u6742\u7684\u4ee3\u7801\u5e93\u800c\u95fb\u540d\u3002\u542f\u7528\u51fd\u6570\u7f13\u5b58\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8 WooCommerce \u5546\u5e97\u7684\u901f\u5ea6\u3002<\/p>\n<ol>\n<li>\u4fee\u6539 WooCommerce \u5546\u5e97\u7684 php.ini \u6587\u4ef6\uff0c\u8bbe\u7f6e\uff1a<\/li>\n<\/ol>\n<pre>opcache.enable = 1\nopcache.memory_consumption = 256<\/pre>\n<ol>\n<li>\u91cd\u542f Web \u670d\u52a1\u5668\u3002<\/li>\n<li>\u6e05\u9664\u7f13\u5b58\uff1a<\/li>\n<\/ol>\n<pre>wp_opcache_invalidate($path, $force = false);<\/pre>\n<p>\u5176\u4e2d <code>$path<\/code> \u662f\u8981\u6e05\u9664\u7684\u7279\u5b9a\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u8def\u5f84\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u9002\u5f53\u914d\u7f6e\u548c\u7ba1\u7406 PHP \u51fd\u6570\u7f13\u5b58\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8 PHP \u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3 \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP\u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u4e0e\u7ba1\u7406\u8be6\u89e3\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ PHP \u51fd\u6570\u7f13\u5b58\u53ef\u901a\u8fc7 php.ini \u914d\u7f6e\uff08opcache.enable \u548c opcache.memory_consumption\uff09\uff0c\u5e76\u53ef\u901a\u8fc7\u68c0\u67e5 phpinfo() \u548c\u4f7f\u7528 opcache_reset() \u51fd\u6570\u6765\u7ba1\u7406\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c\u901a\u8fc7\u542f\u7528\u51fd\u6570\u7f13\u5b58\u5e76\u9002\u5f53\u8bbe\u7f6e WooCommerce \u5546\u5e97\u7684\u5185\u5b58\u6d88\u8017\u91cf\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5176\u901f\u5ea6\u3002 PHP \u51fd\u6570\u7f13\u5b58\u914d\u7f6e\u548c\u7ba1\u7406 \u7b80\u4ecb PHP \u51fd\u6570\u7f13\u5b58\uff08opcode cache\uff09\u7528\u4e8e\u5b58\u50a8\u5df2\u7f16\u8bd1\u7684 PHP \u51fd\u6570\uff0c\u4ece\u800c\u52a0\u5feb\u811a\u672c\u6267\u884c\u901f\u5ea6\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd PHP \u51fd\u6570\u7f13\u5b58\u7684\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5b9e\u6218\u6848\u4f8b\u3002 \u914d\u7f6e \u5728 php.ini \u4e2d\u627e\u5230\u4ee5\u4e0b\u8bbe\u7f6e\uff1a opcache.enable = 1 opcache.memory_consumption = 128 opcache.enable\uff1a\u542f\u7528\u6216\u7981\u7528\u51fd\u6570\u7f13\u5b58\uff0c\u8bbe\u7f6e\u4e3a 1 \u4ee5\u542f\u7528\u3002 opcache.memory_consumption\uff1a\u6307\u5b9a\u51fd\u6570\u7f13\u5b58\u7684\u5185\u5b58\u5360\u7528\u5927\u5c0f\uff08\u4ee5\u5146\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\u3002\u6839\u636e\u7cfb\u7edf\u4e2d\u7684\u53ef\u7528\u5185\u5b58\u548c\u5904\u7406\u7684\u811a\u672c\u6570\u91cf\u8fdb\u884c\u8c03\u6574\u3002 \u7ba1\u7406 \u68c0\u67e5\u72b6\u6001 phpinfo(); \u8f93\u51fa\u4e2d\u67e5\u627e opcache \u90e8\u5206\uff0c\u68c0\u67e5\u4ee5\u4e0b\u4fe1\u606f\uff1a opcache.enabled\uff1a\u663e\u793a\u7f13\u5b58\u662f\u5426\u5df2\u542f\u7528\u3002 opcache.memory_consumption\uff1a\u663e\u793a\u7f13\u5b58\u7684\u5185\u5b58\u5360\u7528\u91cf\u3002 opcache.statistics\uff1a\u63d0\u4f9b\u6709\u5173\u7f13\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u8be6\u7ec6\u7edf\u8ba1\u4fe1\u606f\u3002 \u6e05\u9664\u7f13\u5b58 opcache_reset(); \u5982\u679c\u505a\u4e86\u4ee3\u7801\u66f4\u6539\u6216\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b64\u51fd\u6570\u6e05\u9664\u7f13\u5b58\u5e76\u91cd\u65b0\u7f16\u8bd1\u51fd\u6570\u3002 \u5b9e\u6218\u6848\u4f8b \u4f18\u5316 WooCommerce WooCommerce \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u7535\u5b50\u5546\u52a1\u63d2\u4ef6\uff0c\u4ee5\u5176\u5e9e\u5927\u4e14\u590d\u6742\u7684\u4ee3\u7801\u5e93\u800c\u95fb\u540d\u3002\u542f\u7528\u51fd\u6570\u7f13\u5b58\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8 [&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-48368","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48368","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=48368"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48368\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}