{"id":47466,"date":"2024-12-02T09:47:14","date_gmt":"2024-12-02T01:47:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47466\/"},"modified":"2024-12-02T09:47:14","modified_gmt":"2024-12-02T01:47:14","slug":"php-%e5%87%bd%e6%95%b0%e6%89%a9%e5%b1%95%e7%9a%84%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e7%ad%96%e7%95%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47466\/","title":{"rendered":"PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aPHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\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~<\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u6027\u80fd\u4f18\u5316\u7b56\u7565\u5305\u62ec\uff1a1. \u7f13\u5b58\u6570\u636e\uff0c\u51cf\u5c11\u6570\u636e\u5e93\u8bbf\u95ee\uff1b2. \u5229\u7528 Opcache\uff0c\u5b58\u50a8\u7f16\u8bd1\u540e\u7684\u5b57\u8282\u7801\uff1b3. \u4f18\u5316\u51fd\u6570\u8c03\u7528\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u8ba1\u7b97\uff1b4. \u4f7f\u7528 JIT \u7f16\u8bd1\u5668\uff0c\u7f16\u8bd1\u4ee3\u7801\u4e3a\u673a\u5668\u4ee3\u7801\uff1b5. \u4f7f\u7528\u6269\u5c55\u52a0\u8f7d\u5668\uff0c\u52a8\u6001\u52a0\u8f7d\u6269\u5c55\uff1b6. \u7981\u7528\u672a\u4f7f\u7528\u7684\u6269\u5c55\uff0c\u51cf\u5c11\u5185\u5b58\u5360\u7528\u548c\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729919213671c78ed1403e.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565<\/strong><\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u662f\u6269\u5c55 PHP \u6838\u5fc3\u529f\u80fd\u7684\u4e00\u79cd\u5f3a\u5927\u65b9\u5f0f\u3002\u7136\u800c\uff0c\u5982\u679c\u4e0d\u91c7\u53d6\u9002\u5f53\u7684\u7b56\u7565\uff0c\u5b83\u4eec\u53ef\u80fd\u4f1a\u5bf9\u6027\u80fd\u9020\u6210\u91cd\u5927\u5f71\u54cd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316 PHP \u51fd\u6570\u6269\u5c55\u7684\u7b56\u7565\uff1a<\/p>\n<p><strong>1. \u7f13\u5b58\u6570\u636e<\/strong><\/p>\n<p>\u5bf9\u4e8e\u9700\u8981\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\uff0c\u4f7f\u7528\u7f13\u5b58\u673a\u5236\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u6027\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528 PHP \u5185\u7f6e\u7684\u7f13\u5b58\u51fd\u6570\uff0c\u5982 <code>apc_add()<\/code> \u548c <code>apc_fetch()<\/code>\uff0c\u6216\u5229\u7528\u7b2c\u4e09\u65b9\u7f13\u5b58\u5e93\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong> \u5728\u4e00\u4e2a\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u4e0a\uff0c\u4ea7\u54c1\u4fe1\u606f\u88ab\u9891\u7e41\u8bfb\u53d6\u3002\u5c06\u4ea7\u54c1\u6570\u636e\u7f13\u5b58\u5230\u5185\u5b58\u4e2d\uff0c\u53ef\u4ee5\u51cf\u5c11\u5bf9\u6570\u636e\u5e93\u7684\u8bbf\u95ee\uff0c\u4ece\u800c\u63d0\u9ad8\u9875\u9762\u52a0\u8f7d\u901f\u5ea6\u3002<\/p>\n<p><strong>2. \u5229\u7528 Opcache<\/strong><\/p>\n<p>Opcache \u662f PHP 5.5 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\u5f15\u5165\u7684 opcode \u7f13\u5b58\u673a\u5236\u3002\u5b83\u5c06 PHP \u811a\u672c\u7f16\u8bd1\u4e3a\u5b57\u8282\u7801\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u8c03\u7528\u65f6\u53ef\u4ee5\u5feb\u901f\u6267\u884c\u3002<\/p>\n<p><strong>3. \u4f18\u5316\u51fd\u6570\u8c03\u7528<\/strong><\/p>\n<p>\u907f\u514d\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u6216 I\/O \u64cd\u4f5c\u3002\u5c06\u8fd9\u4e9b\u64cd\u4f5c\u79fb\u5230\u51fd\u6570\u5916\u90e8\u6216\u4f7f\u7528\u60f0\u6027\u6c42\u503c\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong> \u8003\u8651\u4e00\u4e2a\u51fd\u6570\uff0c\u5b83\u83b7\u53d6\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u3002\u5982\u679c\u8fd9\u4e2a\u5c5e\u6027\u7ecf\u5e38\u88ab\u8bbf\u95ee\uff0c\u53ef\u4ee5\u5c06\u5b83\u5b58\u50a8\u5728\u5c40\u90e8\u53d8\u91cf\u4e2d\uff0c\u4ee5\u907f\u514d\u91cd\u590d\u7684\u5bf9\u8c61\u8bbf\u95ee\u3002<\/p>\n<p><strong>4. \u4f7f\u7528 JIT \u7f16\u8bd1\u5668<\/strong><\/p>\n<p>Just-In-Time (JIT) \u7f16\u8bd1\u5668\uff0c\u5982 HHVM\uff0c\u53ef\u4ee5\u5c06 PHP \u4ee3\u7801\u7f16\u8bd1\u4e3a\u673a\u5668\u4ee3\u7801\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u51cf\u5c11\u89e3\u91ca\u5f00\u9500\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong> \u5728\u4e00\u4e2a\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u7f51\u7ad9\u4e0a\uff0c\u4f7f\u7528 JIT \u7f16\u8bd1\u5668\u53ef\u4ee5\u663e\u7740\u6539\u5584\u4ee3\u7801\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<p><strong>5. \u4f7f\u7528\u6269\u5c55\u52a0\u8f7d\u5668<\/strong><\/p>\n<p>PHP \u6269\u5c55\u52a0\u8f7d\u5668\u5141\u8bb8\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u52a0\u8f7d\u6269\u5c55\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u53ea\u52a0\u8f7d\u6240\u9700\u7684\u6269\u5c55\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u52a0\u8f7d\u6240\u6709\u6269\u5c55\u3002<\/p>\n<p><strong>6. \u7981\u7528\u672a\u4f7f\u7528\u7684\u6269\u5c55<\/strong><\/p>\n<p>\u4e0d\u4f7f\u7528\u7684\u6269\u5c55\u4f1a\u5360\u7528\u5185\u5b58\u5e76\u589e\u52a0\u6267\u884c\u65f6\u95f4\u3002\u7981\u7528\u6240\u6709\u672a\u4f7f\u7528\u7684\u6269\u5c55\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<p>\u4f18\u5316 PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u65f6\u95f4\u548c\u541e\u5410\u91cf\u3002\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u7b56\u7565\u5e76\u5229\u7528\u73b0\u4ee3 PHP \u529f\u80fd\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u9ad8\u6548\u4e14\u53ef\u6269\u5c55\u7684\u51fd\u6570\u6269\u5c55\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8ephp,\u6269\u5c55\u4f18\u5316\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f \u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aPHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\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\u6269\u5c55\u6027\u80fd\u4f18\u5316\u7b56\u7565\u5305\u62ec\uff1a1. \u7f13\u5b58\u6570\u636e\uff0c\u51cf\u5c11\u6570\u636e\u5e93\u8bbf\u95ee\uff1b2. \u5229\u7528 Opcache\uff0c\u5b58\u50a8\u7f16\u8bd1\u540e\u7684\u5b57\u8282\u7801\uff1b3. \u4f18\u5316\u51fd\u6570\u8c03\u7528\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u8ba1\u7b97\uff1b4. \u4f7f\u7528 JIT \u7f16\u8bd1\u5668\uff0c\u7f16\u8bd1\u4ee3\u7801\u4e3a\u673a\u5668\u4ee3\u7801\uff1b5. \u4f7f\u7528\u6269\u5c55\u52a0\u8f7d\u5668\uff0c\u52a8\u6001\u52a0\u8f7d\u6269\u5c55\uff1b6. \u7981\u7528\u672a\u4f7f\u7528\u7684\u6269\u5c55\uff0c\u51cf\u5c11\u5185\u5b58\u5360\u7528\u548c\u6267\u884c\u65f6\u95f4\u3002 PHP \u51fd\u6570\u6269\u5c55\u7684\u6027\u80fd\u4f18\u5316\u7b56\u7565 PHP \u51fd\u6570\u6269\u5c55\u662f\u6269\u5c55 PHP \u6838\u5fc3\u529f\u80fd\u7684\u4e00\u79cd\u5f3a\u5927\u65b9\u5f0f\u3002\u7136\u800c\uff0c\u5982\u679c\u4e0d\u91c7\u53d6\u9002\u5f53\u7684\u7b56\u7565\uff0c\u5b83\u4eec\u53ef\u80fd\u4f1a\u5bf9\u6027\u80fd\u9020\u6210\u91cd\u5927\u5f71\u54cd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316 PHP \u51fd\u6570\u6269\u5c55\u7684\u7b56\u7565\uff1a 1. \u7f13\u5b58\u6570\u636e \u5bf9\u4e8e\u9700\u8981\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\uff0c\u4f7f\u7528\u7f13\u5b58\u673a\u5236\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u6027\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528 PHP \u5185\u7f6e\u7684\u7f13\u5b58\u51fd\u6570\uff0c\u5982 apc_add() \u548c apc_fetch()\uff0c\u6216\u5229\u7528\u7b2c\u4e09\u65b9\u7f13\u5b58\u5e93\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a \u5728\u4e00\u4e2a\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u4e0a\uff0c\u4ea7\u54c1\u4fe1\u606f\u88ab\u9891\u7e41\u8bfb\u53d6\u3002\u5c06\u4ea7\u54c1\u6570\u636e\u7f13\u5b58\u5230\u5185\u5b58\u4e2d\uff0c\u53ef\u4ee5\u51cf\u5c11\u5bf9\u6570\u636e\u5e93\u7684\u8bbf\u95ee\uff0c\u4ece\u800c\u63d0\u9ad8\u9875\u9762\u52a0\u8f7d\u901f\u5ea6\u3002 2. \u5229\u7528 Opcache Opcache \u662f PHP 5.5 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\u5f15\u5165\u7684 opcode \u7f13\u5b58\u673a\u5236\u3002\u5b83\u5c06 PHP \u811a\u672c\u7f16\u8bd1\u4e3a\u5b57\u8282\u7801\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u8c03\u7528\u65f6\u53ef\u4ee5\u5feb\u901f\u6267\u884c\u3002 3. \u4f18\u5316\u51fd\u6570\u8c03\u7528 \u907f\u514d\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u6216 I\/O \u64cd\u4f5c\u3002\u5c06\u8fd9\u4e9b\u64cd\u4f5c\u79fb\u5230\u51fd\u6570\u5916\u90e8\u6216\u4f7f\u7528\u60f0\u6027\u6c42\u503c\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a \u8003\u8651\u4e00\u4e2a\u51fd\u6570\uff0c\u5b83\u83b7\u53d6\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u3002\u5982\u679c\u8fd9\u4e2a\u5c5e\u6027\u7ecf\u5e38\u88ab\u8bbf\u95ee\uff0c\u53ef\u4ee5\u5c06\u5b83\u5b58\u50a8\u5728\u5c40\u90e8\u53d8\u91cf\u4e2d\uff0c\u4ee5\u907f\u514d\u91cd\u590d\u7684\u5bf9\u8c61\u8bbf\u95ee\u3002 4. \u4f7f\u7528 JIT [&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-47466","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47466","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=47466"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47466\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}