{"id":47872,"date":"2024-12-02T08:59:06","date_gmt":"2024-12-02T00:59:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47872\/"},"modified":"2024-12-02T08:59:06","modified_gmt":"2024-12-02T00:59:06","slug":"php%e5%87%bd%e6%95%b0%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90%e5%b7%a5%e5%85%b7%e4%bb%8b%e7%bb%8d%ef%bc%9a%e5%a6%82%e4%bd%95%e9%80%89%e6%8b%a9%e5%90%88%e9%80%82%e7%9a%84%e5%b7%a5%e5%85%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47872\/","title":{"rendered":"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u7684\u9009\u62e9\u53d6\u51b3\u4e8e\u9700\u6c42\u3001\u9884\u7b97\u3001\u6613\u7528\u6027\u3001\u96c6\u6210\u548c\u529f\u80fd\u3002\u53ef\u7528\u7684\u5de5\u5177\u5305\u62ec\uff1aXdebug\uff1a\u63d0\u4f9b\u4e30\u5bcc\u7684\u5206\u6790\u4f46\u9700\u542f\u7528 Zend \u6269\u5c55\uff1bTideways\uff1a\u63d0\u4f9b\u6df1\u5165\u7684\u5206\u6790\u4f46\u9700\u4ed8\u8d39\u8ba2\u9605\uff1bBlackfire\uff1a\u63d0\u4f9b\u8be6\u7ec6\u7684\u5206\u6790\u4f46\u9700\u4ed8\u8d39\u8ba2\u9605\uff1bPHP Trace\uff1a\u8f7b\u91cf\u7ea7\u4e14\u6613\u4e8e\u4f7f\u7528\u4f46\u529f\u80fd\u6709\u9650\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729940851671ccd73defa7.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f\u63d2\u56fe\" alt=\"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u9009\u62e9\u6307\u5357<\/h2>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u6027\u80fd\u5206\u6790\u5bf9\u4e8e\u8bc6\u522b\u548c\u6539\u8fdb PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u74f6\u9888\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u53ef\u7528\u4e8e\u5206\u6790 PHP \u51fd\u6570\u6027\u80fd\u7684\u5404\u79cd\u5de5\u5177\uff0c\u5e76\u6307\u5bfc\u60a8\u6839\u636e\u60a8\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u3002<\/p>\n<p><strong>\u53ef\u7528\u5de5\u5177<\/strong><\/p>\n<p><strong>1. Xdebug<\/strong><\/p>\n<ul>\n<li><strong>\u4f18\u70b9\uff1a<\/strong> \u63d0\u4f9b\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5305\u62ec\u4ee3\u7801\u5206\u6790\u3001\u5185\u5b58\u5206\u6790\u548c\u8c03\u8bd5\u3002<\/li>\n<li><strong>\u7f3a\u70b9\uff1a<\/strong> \u9700\u8981\u542f\u7528 Zend \u6269\u5c55\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u6027\u80fd\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u4f7f\u7528 Xdebug \u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4\nini_set('xdebug.profiler_enable', true);\nini_set('xdebug.profiler_output_dir', '\/tmp');\n\nfunction test_function() {\n    \/\/ ...\n}\n\ntest_function();\n\n\/\/ \u5206\u6790\u62a5\u544a\u4f4d\u4e8e \/tmp\/xdebug.profiler.html<\/pre>\n<p><strong>2. Tideways<\/strong><\/p>\n<ul>\n<li><strong>\u4f18\u70b9\uff1a<\/strong> \u5546\u4e1a\u5de5\u5177\uff0c\u63d0\u4f9b\u6df1\u5165\u7684\u6027\u80fd\u5206\u6790\uff0c\u5305\u62ec\u51fd\u6570\u8c03\u7528\u56fe\u548c\u8c03\u7528\u4fe1\u606f\u3002<\/li>\n<li><strong>\u7f3a\u70b9\uff1a<\/strong> \u9700\u8981\u4ed8\u8d39\u8ba2\u9605\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u4f7f\u7528 Tideways \u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4\ntideways_enable();\n\nfunction test_function() {\n    \/\/ ...\n}\n\ntest_function();\n\n\/\/ \u5206\u6790\u62a5\u544a\u53ef\u901a\u8fc7 Tideways \u4eea\u8868\u677f\u8bbf\u95ee<\/pre>\n<p><strong>3. Blackfire<\/strong><\/p>\n<ul>\n<li><strong>\u4f18\u70b9\uff1a<\/strong> \u63d0\u4f9b\u8be6\u7ec6\u7684\u6027\u80fd\u5206\u6790\uff0c\u5305\u62ec\u51fd\u6570\u8c03\u7528\u987a\u5e8f\u548c\u5185\u5b58\u6cc4\u6f0f\u68c0\u6d4b\u3002<\/li>\n<li><strong>\u7f3a\u70b9\uff1a<\/strong> \u9700\u8981\u4ed8\u8d39\u8ba2\u9605\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u4f7f\u7528 Blackfire \u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4\nuse Blackfire\\Client;\n\n$client = Client::getInstance();\n$client-&gt;setApiKey('YOUR_API_KEY');\n\n$profiler = $client-&gt;start();\n\nfunction test_function() {\n    \/\/ ...\n}\n\ntest_function();\n\n\/\/ \u5206\u6790\u62a5\u544a\u53ef\u901a\u8fc7 Blackfire \u7f51\u7ad9\u8bbf\u95ee<\/pre>\n<p><strong>4. PHP Trace<\/strong><\/p>\n<ul>\n<li><strong>\u4f18\u70b9\uff1a<\/strong> \u8f7b\u91cf\u7ea7\u4e14\u6613\u4e8e\u4f7f\u7528\uff0c\u63d0\u4f9b\u51fd\u6570\u8c03\u7528\u8ddf\u8e2a\u548c CPU \u91c7\u6837\u3002<\/li>\n<li><strong>\u7f3a\u70b9\uff1a<\/strong> \u529f\u80fd\u8f83\u6709\u9650\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u4f7f\u7528 PHP Trace \u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4\n$trace = PHP_Trace::get();\n$trace-&gt;start();\n\nfunction test_function() {\n    \/\/ ...\n}\n\ntest_function();\n\n$trace-&gt;stop();\n\n\/\/ \u5206\u6790\u62a5\u544a\u6253\u5370\u5230\u63a7\u5236\u53f0<\/pre>\n<p><strong>\u9009\u62e9\u6807\u51c6<\/strong><\/p>\n<p><strong>\u9700\u6c42\uff1a<\/strong> \u8003\u8651\u60a8\u6240\u9700\u7684\u5206\u6790\u7ea7\u522b\u548c\u529f\u80fd\u3002<br \/><strong>\u9884\u7b97\uff1a<\/strong> \u67d0\u4e9b\u5de5\u5177\u9700\u8981\u4ed8\u8d39\u8ba2\u9605\u3002<br \/><strong>\u6613\u7528\u6027\uff1a<\/strong> \u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u6613\u4e8e\u4f7f\u7528\u7684\u5de5\u5177\u66f4\u5408\u9002\u3002<br \/><strong>\u96c6\u6210\uff1a<\/strong> \u67d0\u4e9b\u5de5\u5177\u53ef\u80fd\u4e0e IDE \u6216 CI\/CD \u6d41\u7a0b\u96c6\u6210\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a PHP \u51fd\u6570\u540d\u4e3a <code>heavy_calculation()<\/code>\uff0c\u6211\u4eec\u60f3\u8981\u5206\u6790\u5176\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<p><strong>\u4f7f\u7528 Xdebug\uff1a<\/strong><\/p>\n<pre>ini_set('xdebug.profiler_enable', true);\nheavy_calculation();\n\/\/ \u5206\u6790\u62a5\u544a\u4f4d\u4e8e \/tmp\/xdebug.profiler.html<\/pre>\n<p><strong>\u4f7f\u7528 Tideways\uff1a<\/strong><\/p>\n<pre>tideways_enable();\nheavy_calculation();\n\/\/ \u5206\u6790\u62a5\u544a\u53ef\u901a\u8fc7 Tideways \u4eea\u8868\u677f\u8bbf\u95ee<\/pre>\n<p>\u901a\u8fc7\u5206\u6790\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\uff0c\u6211\u4eec\u53ef\u4ee5\u627e\u51fa\u74f6\u9888\u5e76\u91c7\u53d6\u63aa\u65bd\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01 PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u7684\u9009\u62e9\u53d6\u51b3\u4e8e\u9700\u6c42\u3001\u9884\u7b97\u3001\u6613\u7528\u6027\u3001\u96c6\u6210\u548c\u529f\u80fd\u3002\u53ef\u7528\u7684\u5de5\u5177\u5305\u62ec\uff1aXdebug\uff1a\u63d0\u4f9b\u4e30\u5bcc\u7684\u5206\u6790\u4f46\u9700\u542f\u7528 Zend \u6269\u5c55\uff1bTideways\uff1a\u63d0\u4f9b\u6df1\u5165\u7684\u5206\u6790\u4f46\u9700\u4ed8\u8d39\u8ba2\u9605\uff1bBlackfire\uff1a\u63d0\u4f9b\u8be6\u7ec6\u7684\u5206\u6790\u4f46\u9700\u4ed8\u8d39\u8ba2\u9605\uff1bPHP Trace\uff1a\u8f7b\u91cf\u7ea7\u4e14\u6613\u4e8e\u4f7f\u7528\u4f46\u529f\u80fd\u6709\u9650\u3002 PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u9009\u62e9\u6307\u5357 \u7b80\u4ecb \u6027\u80fd\u5206\u6790\u5bf9\u4e8e\u8bc6\u522b\u548c\u6539\u8fdb PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u74f6\u9888\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u53ef\u7528\u4e8e\u5206\u6790 PHP \u51fd\u6570\u6027\u80fd\u7684\u5404\u79cd\u5de5\u5177\uff0c\u5e76\u6307\u5bfc\u60a8\u6839\u636e\u60a8\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u3002 \u53ef\u7528\u5de5\u5177 1. Xdebug \u4f18\u70b9\uff1a \u63d0\u4f9b\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5305\u62ec\u4ee3\u7801\u5206\u6790\u3001\u5185\u5b58\u5206\u6790\u548c\u8c03\u8bd5\u3002 \u7f3a\u70b9\uff1a \u9700\u8981\u542f\u7528 Zend \u6269\u5c55\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u6027\u80fd\u3002 \/\/ \u4f7f\u7528 Xdebug \u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4 ini_set(&#8216;xdebug.profiler_enable&#8217;, true); ini_set(&#8216;xdebug.profiler_output_dir&#8217;, &#8216;\/tmp&#8217;); function test_function() { \/\/ &#8230; } test_function(); \/\/ \u5206\u6790\u62a5\u544a\u4f4d\u4e8e \/tmp\/xdebug.profiler.html 2. Tideways \u4f18\u70b9\uff1a \u5546\u4e1a\u5de5\u5177\uff0c\u63d0\u4f9b\u6df1\u5165\u7684\u6027\u80fd\u5206\u6790\uff0c\u5305\u62ec\u51fd\u6570\u8c03\u7528\u56fe\u548c\u8c03\u7528\u4fe1\u606f\u3002 \u7f3a\u70b9\uff1a \u9700\u8981\u4ed8\u8d39\u8ba2\u9605\u3002 \/\/ \u4f7f\u7528 Tideways \u5206\u6790\u51fd\u6570\u6267\u884c\u65f6\u95f4 tideways_enable(); function test_function() [&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-47872","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47872","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=47872"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47872\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}