{"id":48579,"date":"2024-12-02T15:37:36","date_gmt":"2024-12-02T07:37:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48579\/"},"modified":"2024-12-02T15:37:36","modified_gmt":"2024-12-02T07:37:36","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%87%bd%e6%95%b0%e7%bc%93%e5%ad%98%e6%8a%80%e6%9c%af%e7%9a%84%e6%9c%aa%e6%9d%a5%e5%8f%91%e5%b1%95%e8%b6%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48579\/","title":{"rendered":"php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p>PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u901a\u8fc7\u5b58\u50a8\u5df2\u6267\u884c\u51fd\u6570\u7684\u7ed3\u679c\u6765\u63d0\u9ad8\u6027\u80fd\uff0c\u907f\u514d\u4e86\u91cd\u590d\u6267\u884c\u51fd\u6570\u3002PHP\u4e2d\u4e3b\u8981\u6709\u4e24\u79cd\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1aAPC\u548cOpcache\u3002\u5b9e\u6218\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528APC\u6765\u7f13\u5b58\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\uff0c\u5982get_timestamp()\u3002\u51fd\u6570\u7f13\u5b58\u6280\u672f\u6b63\u5728\u53d1\u5c55\uff0c\u4ee5\u63d0\u9ad8\u7f13\u5b58\u80fd\u529b\u3001\u5206\u5e03\u5f0f\u6269\u5c55\u548c\u667a\u80fd\u8bc6\u522b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730090853671f176527209.jpg\" class=\"aligncenter\" title=\"php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u662f\u4e00\u79cd\u7f13\u5b58\u51fd\u6570\u6267\u884c\u7ed3\u679c\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8 PHP \u5e94\u7528\u7684\u6027\u80fd\u3002\u5b83\u901a\u8fc7\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u5df2\u6267\u884c\u51fd\u6570\u7684\u7ed3\u679c\uff0c\u907f\u514d\u4e86\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u90fd\u9700\u8981\u91cd\u65b0\u6267\u884c\u4ee3\u7801\u7684\u8fc7\u7a0b\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u6267\u884c\u65f6\u95f4\u548c\u8d44\u6e90\u6d88\u8017\u3002<\/p>\n<p><strong>\u4e24\u79cd\u4e3b\u8981\u7684\u6280\u672f<\/strong><\/p>\n<p>PHP \u4e2d\u6709\u4e24\u79cd\u4e3b\u8981\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1a<\/p>\n<ul>\n<li><strong>APC (Alternative PHP Cache)<\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a\u7531 PECL \u63d0\u4f9b\u7684\u6269\u5c55\uff0c\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u7f13\u5b58 API\u3002<\/li>\n<li><strong>Opcache<\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a Zend Engine \u5185\u7f6e\u7684\u4f18\u5316\u5668\uff0c\u5b83\u9488\u5bf9 Zend Optimizer+ \u8fdb\u884c\u4f18\u5316\uff0c\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u7f13\u5b58\u673a\u5236\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 APC \u6765\u7f13\u5b58\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\uff1a<\/p>\n<pre>\/\/ \u542f\u7528 APC \u6269\u5c55\nini_set('apc.enabled', 1);\n\n\/\/ \u5b9a\u4e49\u8981\u7f13\u5b58\u7684\u51fd\u6570\nfunction get_timestamp() {\n  return time();\n}\n\n\/\/ \u4f7f\u7528 APC \u7f13\u5b58\u51fd\u6570\u7ed3\u679c\n$timestamp = apc_fetch('timestamp');\n\n\/\/ \u5982\u679c\u7f13\u5b58\u4e2d\u6ca1\u6709\u7ed3\u679c\uff0c\u5219\u6267\u884c\u51fd\u6570\u5e76\u5b58\u50a8\u7ed3\u679c\nif (!$timestamp) {\n  $timestamp = get_timestamp();\n  apc_store('timestamp', $timestamp);\n}\n\necho $timestamp;<\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>get_timestamp()<\/code> \u51fd\u6570\u88ab\u7f13\u5b58\u4e3a <code>timestamp<\/code> \u952e\u3002\u5f53\u4e0b\u6b21\u8c03\u7528\u5b83\u65f6\uff0cAPC \u5c06\u4ece\u7f13\u5b58\u4e2d\u68c0\u7d22\u7ed3\u679c\uff0c\u800c\u4e0d\u662f\u91cd\u65b0\u6267\u884c\u51fd\u6570\u3002<\/p>\n<p><strong>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u53d1\u5c55\u8d8b\u52bf<\/strong><\/p>\n<p>\u51fd\u6570\u7f13\u5b58\u6280\u672f\u6b63\u5728\u4e0d\u65ad\u53d1\u5c55\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u548c\u529f\u80fd\uff1a<\/p>\n<ul>\n<li><strong>\u66f4\u9ad8\u7ea7\u522b\u7684\u7f13\u5b58<\/strong>: \u9664\u4e86\u51fd\u6570\u7ed3\u679c\u4e4b\u5916\uff0c\u7f13\u5b58\u6280\u672f\u8fd8\u53ef\u80fd\u6269\u5c55\u5230\u7f13\u5b58\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\uff0c\u4f8b\u5982\u5bf9\u8c61\u548c\u6570\u636e\u5e93\u67e5\u8be2\u3002<\/li>\n<li><strong>\u5206\u5e03\u5f0f\u7f13\u5b58<\/strong>: \u5bf9\u4e8e\u9700\u8981\u5904\u7406\u5927\u91cf\u7f13\u5b58\u6570\u636e\u7684\u7cfb\u7edf\uff0c\u5206\u5e03\u5f0f\u7f13\u5b58\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u63d0\u4f9b\u53ef\u4f38\u7f29\u6027\u548c\u9ad8\u53ef\u7528\u6027\u3002<\/li>\n<li><strong>\u667a\u80fd\u7f13\u5b58<\/strong>: \u901a\u8fc7\u4f7f\u7528\u673a\u5668\u5b66\u4e60\u6216\u5176\u4ed6\u6280\u672f\uff0c\u7f13\u5b58\u7cfb\u7edf\u53ef\u4ee5\u81ea\u52a8\u8bc6\u522b\u548c\u7f13\u5b58\u9700\u8981\u7ecf\u5e38\u6267\u884c\u7684\u51fd\u6570\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u4f18\u5316\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300aphp \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3\uff1a\u51fd\u6570\u7f13\u5b58\u6280\u672f\u7684\u672a\u6765\u53d1\u5c55\u8d8b\u52bf\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 PHP\u51fd\u6570\u7f13\u5b58\u6280\u672f\u901a\u8fc7\u5b58\u50a8\u5df2\u6267\u884c\u51fd\u6570\u7684\u7ed3\u679c\u6765\u63d0\u9ad8\u6027\u80fd\uff0c\u907f\u514d\u4e86\u91cd\u590d\u6267\u884c\u51fd\u6570\u3002PHP\u4e2d\u4e3b\u8981\u6709\u4e24\u79cd\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1aAPC\u548cOpcache\u3002\u5b9e\u6218\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528APC\u6765\u7f13\u5b58\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\uff0c\u5982get_timestamp()\u3002\u51fd\u6570\u7f13\u5b58\u6280\u672f\u6b63\u5728\u53d1\u5c55\uff0c\u4ee5\u63d0\u9ad8\u7f13\u5b58\u80fd\u529b\u3001\u5206\u5e03\u5f0f\u6269\u5c55\u548c\u667a\u80fd\u8bc6\u522b\u3002 PHP \u51fd\u6570\u7f13\u5b58\u6280\u672f\u8be6\u89e3 \u7b80\u4ecb \u51fd\u6570\u7f13\u5b58\u6280\u672f\u662f\u4e00\u79cd\u7f13\u5b58\u51fd\u6570\u6267\u884c\u7ed3\u679c\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8 PHP \u5e94\u7528\u7684\u6027\u80fd\u3002\u5b83\u901a\u8fc7\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u5df2\u6267\u884c\u51fd\u6570\u7684\u7ed3\u679c\uff0c\u907f\u514d\u4e86\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u90fd\u9700\u8981\u91cd\u65b0\u6267\u884c\u4ee3\u7801\u7684\u8fc7\u7a0b\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u6267\u884c\u65f6\u95f4\u548c\u8d44\u6e90\u6d88\u8017\u3002 \u4e24\u79cd\u4e3b\u8981\u7684\u6280\u672f PHP \u4e2d\u6709\u4e24\u79cd\u4e3b\u8981\u7684\u51fd\u6570\u7f13\u5b58\u6280\u672f\uff1a APC (Alternative PHP Cache)\uff1a\u8fd9\u662f\u4e00\u4e2a\u7531 PECL \u63d0\u4f9b\u7684\u6269\u5c55\uff0c\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u7f13\u5b58 API\u3002 Opcache\uff1a\u8fd9\u662f\u4e00\u4e2a Zend Engine \u5185\u7f6e\u7684\u4f18\u5316\u5668\uff0c\u5b83\u9488\u5bf9 Zend Optimizer+ \u8fdb\u884c\u4f18\u5316\uff0c\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u7f13\u5b58\u673a\u5236\u3002 \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 APC \u6765\u7f13\u5b58\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\uff1a \/\/ \u542f\u7528 APC \u6269\u5c55 ini_set(&#8216;apc.enabled&#8217;, 1); \/\/ \u5b9a\u4e49\u8981\u7f13\u5b58\u7684\u51fd\u6570 function get_timestamp() { return time(); } \/\/ \u4f7f\u7528 APC \u7f13\u5b58\u51fd\u6570\u7ed3\u679c $timestamp = apc_fetch(&#8216;timestamp&#8217;); \/\/ \u5982\u679c\u7f13\u5b58\u4e2d\u6ca1\u6709\u7ed3\u679c\uff0c\u5219\u6267\u884c\u51fd\u6570\u5e76\u5b58\u50a8\u7ed3\u679c [&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-48579","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48579","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=48579"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48579\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}