{"id":202398,"date":"2025-05-13T09:43:16","date_gmt":"2025-05-13T01:43:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202398\/"},"modified":"2025-05-13T09:43:16","modified_gmt":"2025-05-13T01:43:16","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%e5%9c%a8%e5%ae%9e%e9%99%85%e9%a1%b9%e7%9b%ae%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202398\/","title":{"rendered":"php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u4f7f\u7528\u51fd\u6570\u7f13\u5b58\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u4f7f\u7528\u51fd\u6570\u7f13\u5b58\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u4f7f\u7528\u51fd\u6570\u7f13\u5b58\uff1f\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~<\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u662f\u4e00\u79cd\u4f18\u5316\u6280\u672f\uff0c\u5c06\u7f16\u8bd1\u540e\u7684\u51fd\u6570\u7ed3\u679c\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u7528\u4e8e\u540e\u7eed\u8c03\u7528\uff0c\u51cf\u5c11\u786c\u76d8\u6216\u6570\u636e\u5e93\u8bbf\u95ee\uff0c\u663e\u8457\u63d0\u9ad8\u51fd\u6570\u6267\u884c\u901f\u5ea6\u3002PHP \u63d0\u4f9b\u4e86 APC\u3001XCache\u3001Memcached\u3001Redis \u7b49\u51fd\u6570\u7f13\u5b58\u6269\u5c55\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c\u53ef\u4f7f\u7528 APC \u7f13\u5b58 fibonacci \u51fd\u6570\u7ed3\u679c\uff0c\u9996\u6b21\u8c03\u7528\u65f6\u7f13\u5b58\u7ed3\u679c\uff0c\u540e\u7eed\u8c03\u7528\u76f4\u63a5\u4ece\u7f13\u5b58\u83b7\u53d6\u3002\u9664\u4e0a\u8ff0\u6269\u5c55\u5916\uff0cPHP Opcache\u3001Zend Optimizer+\u3001HHVM \u7b49\u65b9\u6cd5\u4e5f\u53ef\u5b9e\u73b0\u51fd\u6570\u7f13\u5b58\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u4ec5\u7f13\u5b58\u6d88\u8017\u8d44\u6e90\u5927\u7684\u51fd\u6570\u3001\u76d1\u63a7\u7f13\u5b58\u4f7f\u7528\u60c5\u51b5\u3001\u5b9a\u671f\u6e05\u7406\u672a\u4f7f\u7528\u7f13\u5b58\u6761\u76ee\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241011\/172865470867092d74e98ee.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>PHP \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u51fd\u6570\u7f13\u5b58\uff1f<\/strong><\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u662f\u4e00\u79cd\u4f18\u5316\u6280\u672f\uff0c\u5b83\u5c06\u7f16\u8bd1\u540e\u7684\u51fd\u6570\u7ed3\u679c\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u7528\u4e8e\u540e\u7eed\u8c03\u7528\u3002\u8fd9\u53ef\u4ee5\u6709\u6548\u5730\u51cf\u5c11\u5bf9\u786c\u76d8\u6216\u6570\u636e\u5e93\u7684\u8bbf\u95ee\uff0c\u4ece\u800c\u663e\u8457\u63d0\u9ad8\u51fd\u6570\u6267\u884c\u901f\u5ea6\u3002<\/p>\n<p><strong>PHP \u4e2d\u7684\u51fd\u6570\u7f13\u5b58<\/strong><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u591a\u79cd\u51fd\u6570\u7f13\u5b58\u6269\u5c55\uff1a<\/p>\n<ul>\n<li><strong>APC (Alternative PHP Cache)<\/strong>\uff1a\u4e0d\u518d\u6d3b\u8dc3\u7ef4\u62a4\uff0c\u4f46\u4ecd\u5e7f\u6cdb\u4f7f\u7528\u3002<\/li>\n<li><strong>XCache<\/strong>\uff1a\u529f\u80fd\u4e30\u5bcc\uff0c\u4f46\u5546\u4e1a\u7248\u672c\u9700\u8981\u4ed8\u8d39\u3002<\/li>\n<li><strong>Memcached<\/strong>\uff1a\u5f3a\u5927\u7684\u5206\u5e03\u5f0f\u7f13\u5b58\u7cfb\u7edf\uff0c\u53ef\u4ee5\u7528\u4e8e\u51fd\u6570\u7f13\u5b58\u3002<\/li>\n<li><strong>Redis<\/strong>\uff1a\u4e00\u4e2a\u6d41\u884c\u7684\u952e\u503c\u5b58\u50a8\uff0c\u4e5f\u53ef\u7528\u4e8e\u51fd\u6570\u7f13\u5b58\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u4f7f\u7528 APC \u8fdb\u884c\u51fd\u6570\u7f13\u5b58<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 APC \u5bf9 PHP \u51fd\u6570\u8fdb\u884c\u7f13\u5b58\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>\/\/ \u542f\u7528 APC \u6269\u5c55\nini_set('apc.enabled', 1);\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u51fd\u6570\nfunction fibonacci($n) {\n  if ($n &lt; 2) {\n    return $n;\n  } else {\n    return fibonacci($n - 1) + fibonacci($n - 2);\n  }\n}\n\n\/\/ \u7f13\u5b58\u51fd\u6570\u7ed3\u679c\napc_add('fibonacci_' . $n, fibonacci($n));\n\n\/\/ \u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u51fd\u6570\u7ed3\u679c\n$result = apc_fetch('fibonacci_' . $n);\n\necho $result;<\/pre>\n<p>\u5728\u7b2c\u4e00\u6b21\u8c03\u7528 <code>fibonacci<\/code> \u51fd\u6570\u65f6\uff0c\u7ed3\u679c\u5c06\u88ab\u7f13\u5b58\u3002\u5728\u540e\u7eed\u8c03\u7528\u4e2d\uff0c\u7ed3\u679c\u5c06\u76f4\u63a5\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\uff0c\u65e0\u9700\u91cd\u65b0\u8ba1\u7b97\u3002<\/p>\n<p><strong>\u5176\u4ed6\u51fd\u6570\u7f13\u5b58\u6280\u672f<\/strong><\/p>\n<p>\u9664\u4e86\u4e0a\u8ff0\u6269\u5c55\u4e4b\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u51fd\u6570\u7f13\u5b58\uff1a<\/p>\n<ul>\n<li><strong>PHP Opcache<\/strong>\uff1aPHP 5.5 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\u5185\u7f6e\u7684\u51fd\u6570\u7f13\u5b58\u5668\u3002<\/li>\n<li><strong>Zend Optimizer+<\/strong>\uff1aZend Technologies \u5f00\u53d1\u7684\u5546\u4e1a\u51fd\u6570\u7f13\u5b58\u89e3\u51b3\u65b9\u6848\u3002<\/li>\n<li><strong>HHVM (HipHop Virtual Machine)<\/strong>\uff1a\u4e00\u79cd\u5c06 PHP \u7f16\u8bd1\u4e3a C++ \u7684\u865a\u62df\u673a\uff0c\u5305\u62ec\u51fd\u6570\u7f13\u5b58\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<ul>\n<li>\u53ea\u7f13\u5b58\u6d88\u8017\u8d44\u6e90\u8f83\u5927\u7684\u51fd\u6570\u3002<\/li>\n<li>\u76d1\u63a7\u7f13\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u786e\u4fdd\u6ca1\u6709\u6ea2\u51fa\u3002<\/li>\n<li>\u5b9a\u671f\u6e05\u7406\u4e0d\u5728\u4f7f\u7528\u7684\u7f13\u5b58\u6761\u76ee\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5173\u4e8e\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u4f7f\u7528\u51fd\u6570\u7f13\u5b58\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u5982\u4f55\u5728&#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-202398","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202398","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=202398"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202398\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}