{"id":47351,"date":"2024-12-02T12:02:30","date_gmt":"2024-12-02T04:02:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47351\/"},"modified":"2024-12-02T12:02:30","modified_gmt":"2024-12-02T04:02:30","slug":"php%e5%87%bd%e6%95%b0%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90%e4%b8%8e%e4%bc%98%e5%8c%96%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47351\/","title":{"rendered":"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p>\u4e3a\u4e86\u4f18\u5316 PHP \u51fd\u6570\u6027\u80fd\uff0c\u9996\u5148\u8981\u5206\u6790\u51fd\u6570\u6027\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5de5\u5177\uff1aPHP profilexhprofBlackfire\u5206\u6790\u540e\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\u4f18\u5316\u6027\u80fd\uff1a\u5907\u5fd8\u5f55\u5316\u8fed\u4ee3\u4f18\u5316\u7b97\u6cd5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729912185671c5d79baa08.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357\u63d2\u56fe\" alt=\"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u51fd\u6570\u7684\u6027\u80fd\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u65f6\u95f4\u548c\u7528\u6237\u4f53\u9a8c\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u5206\u6790 PHP \u51fd\u6570\u7684\u6027\u80fd\u5e76\u8fdb\u884c\u4f18\u5316\u4ee5\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<p><strong>\u5206\u6790\u51fd\u6570\u6027\u80fd<\/strong><\/p>\n<p>\u4e3a\u4e86\u5206\u6790\u51fd\u6570\u6027\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5de5\u5177\uff1a<\/p>\n<ul>\n<li><strong>PHP profile<\/strong>\uff1a \u5185\u7f6e\u6269\u5c55\uff0c\u7528\u4e8e\u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4\u548c\u5185\u5b58\u6d88\u8017\u3002<\/li>\n<li><strong>xhprof<\/strong>\uff1a \u9644\u52a0\u6a21\u5757\uff0c\u63d0\u4f9b\u66f4\u8be6\u7ec6\u7684\u6027\u80fd\u5206\u6790\uff0c\u5305\u62ec\u8c03\u7528\u56fe\u548c\u706b\u7130\u56fe\u3002<\/li>\n<li><strong>Blackfire<\/strong>\uff1a \u5546\u4e1a\u5de5\u5177\uff0c\u63d0\u4f9b\u9ad8\u7ea7\u6027\u80fd\u5206\u6790\u548c\u4f18\u5316\u5efa\u8bae\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u51fd\u6570\uff1a<\/p>\n<pre>function compute_factorial($n) {\n  if ($n == 0) {\n    return 1;\n  } else {\n    return $n * compute_factorial($n - 1);\n  }\n}<\/pre>\n<p>\u4f7f\u7528 <code>PHP profile<\/code> \u5206\u6790\u6b64\u51fd\u6570\uff0c\u6211\u4eec\u53d1\u73b0\u9012\u5f52\u8c03\u7528\u9020\u6210\u4e86\u6027\u80fd\u5f00\u9500\uff1a<\/p>\n<pre>+--------------+---------------+----------------------+---------------------+\n| Function Name | Calls          | Time (Self)          | Time (Total)         |\n+--------------+---------------+----------------------+---------------------+\n| compute_fact | 1406          | 14.239 ms            | 28.573 ms            |\n| compute_fact | 1407          | 14.231 ms            | 28.536 ms            |\n| compute_fact | 1408          | 14.202 ms            | 28.478 ms            |\n| ...          | ...            | ...                  | ...                  |<\/pre>\n<p><strong>\u6027\u80fd\u4f18\u5316<\/strong><\/p>\n<p>\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\uff1a<\/p>\n<ul>\n<li><strong>\u5907\u5fd8\u5f55\u5316<\/strong>\uff1a \u4f7f\u7528\u6570\u7ec4\u5b58\u50a8\u51fd\u6570\u8c03\u7528\u7684\u7ed3\u679c\uff0c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u3002<\/li>\n<li><strong>\u8fed\u4ee3<\/strong>\uff1a \u5c06\u9012\u5f52\u7b97\u6cd5\u8f6c\u6362\u4e3a\u8fed\u4ee3\u7b97\u6cd5\uff0c\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u5f00\u9500\u3002<\/li>\n<li><strong>\u4f18\u5316\u7b97\u6cd5<\/strong>\uff1a \u8003\u8651\u66f4\u6709\u6548\u7684\u7b97\u6cd5\uff0c\u4f8b\u5982\u4f7f\u7528\u95ed\u5305\u6216\u751f\u6210\u5668\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\u4f18\u5316<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5907\u5fd8\u5f55\u5316\u6765\u4f18\u5316 <code>compute_factorial<\/code> \u51fd\u6570\uff1a<\/p>\n<pre>function compute_factorial_optimized($n) {\n  $factorial = [0 =&gt; 1];\n  if ($n == 0) {\n    return $factorial[0];\n  } else {\n    if (!isset($factorial[$n])) {\n      $factorial[$n] = $n * compute_factorial($n - 1);\n    }\n    return $factorial[$n];\n  }\n}<\/pre>\n<p>\u5206\u6790\u7ecf\u8fc7\u4f18\u5316\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u770b\u5230\u6027\u80fd\u663e\u8457\u63d0\u9ad8\uff1a<\/p>\n<pre>+--------------+---------------+----------------------+---------------------+\n| Function Name | Calls          | Time (Self)          | Time (Total)         |\n+--------------+---------------+----------------------+---------------------+\n| comp_fact_opt | 1406          | 0.526 ms             | 0.526 ms             |\n| ...          | ...            | ...                  | ...                  |<\/pre>\n<p><strong>Conclusion<\/strong><\/p>\n<p>\u901a\u8fc7\u5206\u6790\u51fd\u6570\u6027\u80fd\u5e76\u5e94\u7528\u4f18\u5316\u7b56\u7565\uff0c\u60a8\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8 PHP \u51fd\u6570\u7684\u6548\u7387\u3002\u8fd9\u5c06\u8f6c\u5316\u4e3a\u66f4\u5feb\u7684\u5e94\u7528\u7a0b\u5e8f\u548c\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ephp,\u4f18\u5316\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357 \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b \u4e3a\u4e86\u4f18\u5316 PHP \u51fd\u6570\u6027\u80fd\uff0c\u9996\u5148\u8981\u5206\u6790\u51fd\u6570\u6027\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5de5\u5177\uff1aPHP profilexhprofBlackfire\u5206\u6790\u540e\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\u4f18\u5316\u6027\u80fd\uff1a\u5907\u5fd8\u5f55\u5316\u8fed\u4ee3\u4f18\u5316\u7b97\u6cd5 PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u4e0e\u4f18\u5316\u6307\u5357 \u7b80\u4ecb PHP \u51fd\u6570\u7684\u6027\u80fd\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u65f6\u95f4\u548c\u7528\u6237\u4f53\u9a8c\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u5206\u6790 PHP \u51fd\u6570\u7684\u6027\u80fd\u5e76\u8fdb\u884c\u4f18\u5316\u4ee5\u63d0\u9ad8\u6548\u7387\u3002 \u5206\u6790\u51fd\u6570\u6027\u80fd \u4e3a\u4e86\u5206\u6790\u51fd\u6570\u6027\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5de5\u5177\uff1a PHP profile\uff1a \u5185\u7f6e\u6269\u5c55\uff0c\u7528\u4e8e\u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4\u548c\u5185\u5b58\u6d88\u8017\u3002 xhprof\uff1a \u9644\u52a0\u6a21\u5757\uff0c\u63d0\u4f9b\u66f4\u8be6\u7ec6\u7684\u6027\u80fd\u5206\u6790\uff0c\u5305\u62ec\u8c03\u7528\u56fe\u548c\u706b\u7130\u56fe\u3002 Blackfire\uff1a \u5546\u4e1a\u5de5\u5177\uff0c\u63d0\u4f9b\u9ad8\u7ea7\u6027\u80fd\u5206\u6790\u548c\u4f18\u5316\u5efa\u8bae\u3002 \u5b9e\u6218\u6848\u4f8b \u8003\u8651\u4ee5\u4e0b\u51fd\u6570\uff1a function compute_factorial($n) { if ($n == 0) { return 1; } else { return $n * compute_factorial($n &#8211; 1); } } \u4f7f\u7528 PHP profile \u5206\u6790\u6b64\u51fd\u6570\uff0c\u6211\u4eec\u53d1\u73b0\u9012\u5f52\u8c03\u7528\u9020\u6210\u4e86\u6027\u80fd\u5f00\u9500\uff1a +&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ | Function Name | Calls [&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-47351","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47351","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=47351"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47351\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}