{"id":202486,"date":"2025-05-13T14:49:45","date_gmt":"2025-05-13T06:49:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202486\/"},"modified":"2025-05-13T14:49:45","modified_gmt":"2025-05-13T06:49:45","slug":"php-%e5%87%bd%e6%95%b0%e7%bc%93%e5%ad%98%e6%8a%80%e6%9c%af%e8%af%a6%e8%a7%a3%ef%bc%9a%e5%a6%82%e4%bd%95%e9%80%89%e6%8b%a9%e9%80%82%e7%94%a8%e4%ba%8e%e7%89%b9%e5%ae%9a%e9%a1%b9%e7%9b%ae%e7%9a%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202486\/","title":{"rendered":"php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u9009\u62e9\u9002\u7528\u4e8e\u7279\u5b9a\u9879\u76ee\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u9009\u62e9\u9002\u7528\u4e8e\u7279\u5b9a\u9879\u76ee\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u9009\u62e9\u9002\u7528\u4e8e\u7279\u5b9a\u9879\u76ee\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u901a\u8fc7\u5b58\u50a8\u51fd\u6570\u8c03\u7528\u7684\u7ed3\u679c\u6765\u63d0\u9ad8 PHP \u5e94\u7528\u6027\u80fd\u3002\u4e09\u79cd\u4e3b\u8981\u7c7b\u578b\u5305\u62ec\uff1a1. \u5185\u5b58\u7f13\u5b58\uff08\u6700\u5feb\uff0c\u4f46\u9700\u8981\u9884\u7f16\u8bd1\u4ee3\u7801\uff09\uff1b2. \u5bf9\u8c61\u7f13\u5b58\uff08\u5141\u8bb8\u8de8\u670d\u52a1\u5668\u5171\u4eab\uff0c\u4f46\u53ef\u80fd\u9700\u8981\u989d\u5916\u6210\u672c\uff09\uff1b3. \u6587\u4ef6\u7f13\u5b58\uff08\u9002\u7528\u4e8e\u8f7b\u91cf\u7ea7\u4e14\u4e0d\u53d7\u9891\u7e41\u66f4\u65b0\u5f71\u54cd\u7684\u5e94\u7528\u7a0b\u5e8f\uff09\u3002\u9009\u62e9\u6700\u4f73\u6280\u672f\u53d6\u51b3\u4e8e\u6027\u80fd\u8981\u6c42\u3001\u53ef\u6269\u5c55\u6027\u3001\u6210\u672c\u548c\u652f\u6301\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729838793671b3ec97cbdc.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>PHP \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u662f\u4e00\u79cd\u6280\u672f\uff0c\u7528\u4e8e\u7f13\u5b58\u51fd\u6570\u8c03\u7528\u7684\u7ed3\u679c\uff0c\u4ece\u800c\u5728\u540e\u7eed\u8bf7\u6c42\u671f\u95f4\u907f\u514d\u91cd\u65b0\u8ba1\u7b97\u3002\u8fd9\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8 PHP \u5e94\u7528\u7684\u6027\u80fd\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u9891\u7e41\u8c03\u7528\u7684\u8ba1\u7b97\u5bc6\u96c6\u578b\u51fd\u6570\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u4e0d\u540c\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff0c\u5e76\u6307\u5bfc\u60a8\u6839\u636e\u9879\u76ee\u9700\u8981\u9009\u62e9\u6700\u4f73\u6280\u672f\u3002<\/p>\n<p><strong>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7c7b\u578b<\/strong><\/p>\n<p><strong>1. \u5185\u5b58\u7f13\u5b58<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 PHP \u672c\u5730\u51fd\u6570\u7f13\u5b58\u6269\u5c55 (opcache)<\/li>\n<li>\u5c06\u51fd\u6570\u5b57\u8282\u7801\u5b58\u50a8\u5728\u5171\u4eab\u5185\u5b58\u4e2d<\/li>\n<li>\u6700\u5feb\u4f46\u9700\u8981\u9884\u7f16\u8bd1 PHP \u4ee3\u7801<\/li>\n<\/ul>\n<p><strong>2. \u5bf9\u8c61\u7f13\u5b58<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 Memcached\u3001Redis \u6216\u5176\u4ed6\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93<\/li>\n<li>\u5c06\u51fd\u6570\u8c03\u7528\u5b58\u50a8\u4e3a\u952e\u503c\u5bf9<\/li>\n<li>\u5141\u8bb8\u5728\u4e0d\u540c\u670d\u52a1\u5668\u4e4b\u95f4\u5171\u4eab\u7f13\u5b58<\/li>\n<\/ul>\n<p><strong>3. \u6587\u4ef6\u7f13\u5b58<\/strong><\/p>\n<ul>\n<li>\u5c06\u51fd\u6570\u8c03\u7528\u5e8f\u5217\u5316\u7684\u7ed3\u679c\u5199\u5165\u6587\u4ef6<\/li>\n<li>\u9002\u7528\u4e8e\u8f7b\u91cf\u7ea7\u548c\u4e0d\u53d7\u9891\u7e41\u66f4\u65b0\u7684\u5f71\u54cd\u7684\u5e94\u7528\u7a0b\u5e8f<\/li>\n<\/ul>\n<p><strong>\u9009\u62e9\u6700\u4f73\u6280\u672f<\/strong><\/p>\n<p>\u9009\u62e9\u51fd\u6570\u7f13\u5b58\u6280\u672f\u53d6\u51b3\u4e8e\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u8981\u6c42\uff1a<\/strong> \u5185\u5b58\u7f13\u5b58\u63d0\u4f9b\u6700\u4f73\u6027\u80fd\uff0c\u5176\u6b21\u662f\u5bf9\u8c61\u7f13\u5b58\uff0c\u7136\u540e\u662f\u6587\u4ef6\u7f13\u5b58\u3002<\/li>\n<li><strong>\u53ef\u6269\u5c55\u6027\uff1a<\/strong> \u5bf9\u8c61\u7f13\u5b58\u5141\u8bb8\u5728\u4e0d\u540c\u670d\u52a1\u5668\u4e4b\u95f4\u5171\u4eab\u7f13\u5b58\uff0c\u4fbf\u4e8e\u6269\u5c55\u3002<\/li>\n<li><strong>\u6210\u672c\uff1a<\/strong> \u5185\u5b58\u7f13\u5b58\u901a\u5e38\u662f\u514d\u8d39\u7684\uff08\u7531 PHP \u6838\u5fc3\u63d0\u4f9b\uff09\uff0c\u800c\u5bf9\u8c61\u7f13\u5b58\u53ef\u80fd\u9700\u8981\u989d\u5916\u7684\u57fa\u7840\u8bbe\u65bd\u6210\u672c\u3002<\/li>\n<li><strong>\u652f\u6301\u6027\uff1a<\/strong> \u9009\u62e9\u5177\u6709\u5e7f\u6cdb\u652f\u6301\u548c\u793e\u533a\u7684\u6210\u719f\u6280\u672f\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u52a0\u8f7d\u9891\u7e41\u4f7f\u7528\u7684\u5305\u542b\u6587\u4ef6<\/strong><\/p>\n<p><strong>\u4f7f\u7528 opcache<\/strong><\/p>\n<pre>&lt;?php\nif (!function_exists('load_file')) {\n    function load_file($path) {\n        require_once $path;\n    }\n}<\/pre>\n<p><strong>\u4f7f\u7528 Memcached<\/strong><\/p>\n<pre>&lt;?php\n$memcached = new Memcached();\n$memcached-&gt;addServer('localhost', 11211);\n\n$file_key = md5($path);\n$file_value = $memcached-&gt;get($file_key);\nif (!$file_value) {\n    $file_value = file_get_contents($path);\n    $memcached-&gt;set($file_key, $file_value);\n}\n\ncache::load_file($path, $file_value);<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u9009\u62e9\u9002\u7528\u4e8e\u7279\u5b9a\u9879\u76ee\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1f\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\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ephp,\u51fd\u6570\u7f13\u5b58\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u9009&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202486","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202486"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202486\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}