{"id":47339,"date":"2024-12-02T15:32:07","date_gmt":"2024-12-02T07:32:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47339\/"},"modified":"2024-12-02T15:32:07","modified_gmt":"2024-12-02T07:32:07","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%e8%bf%9b%e8%a1%8c%e5%88%86%e6%9e%90%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47339\/","title":{"rendered":"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f<\/h1>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587<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\u8fdb\u884c\u5206\u6790\uff1f\u300b<\/span>\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729911810671c5c0292397.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f\u63d2\u56fe\" alt=\"php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u52a9\u4f60\u6df1\u5165\u63a2\u7a76\u51fd\u6570\u8fd0\u884c<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u4f5c\u4e3a PHP \u5f00\u53d1\u4eba\u5458\uff0c\u4e3a\u4e86\u4f18\u5316\u4ee3\u7801\u6027\u80fd\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5206\u6790\u51fd\u6570\u7684\u6267\u884c\u60c5\u51b5\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u4e2a\u5b9e\u7528\u7684 PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u5e2e\u52a9\u4f60\u6df1\u5165\u63a2\u7a76\u51fd\u6570\u7684\u8fd0\u884c\uff0c\u627e\u51fa\u6027\u80fd\u74f6\u9888\u5e76\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n<p><strong>\u5de5\u5177\u4ecb\u7ecd<\/strong><\/p>\n<p><strong>1. PHP Profiling \u5de5\u5177\u5305<\/strong><\/p>\n<p>PHP Profiling \u5de5\u5177\u5305\u662f PHP \u5185\u7f6e\u7684\u4e00\u4e2a\u5f3a\u5927\u5de5\u5177\uff0c\u53ef\u4ee5\u751f\u6210\u51fd\u6570\u8c03\u7528\u548c\u8d44\u6e90\u6d88\u8017\u7684\u8be6\u7ec6\u5206\u6790\u62a5\u544a\u3002\u5b83\u662f\u5185\u7f6e\u4e8e PHP \u6838\u5fc3\u4e2d\u7684\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u5b89\u88c5\u989d\u5916\u7684\u6269\u5c55\u3002<\/p>\n<p><strong>2. Xdebug<\/strong><\/p>\n<p>Xdebug \u662f\u4e00\u4e2a\u6d41\u884c\u7684 PHP \u8c03\u8bd5\u548c\u5206\u6790\u6269\u5c55\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5305\u62ec\u6027\u80fd\u5206\u6790\u3002\u5b83\u53ef\u4ee5\u8ddf\u8e2a\u51fd\u6570\u8c03\u7528\u5e76\u663e\u793a\u6bcf\u4e2a\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u548c\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<p><strong>3. Blackfire.io<\/strong><\/p>\n<p>Blackfire.io \u662f\u4e00\u4e2a\u57fa\u4e8e\u4e91\u7684 PHP \u6027\u80fd\u5206\u6790\u5e73\u53f0\uff0c\u63d0\u4f9b\u4ea4\u4e92\u5f0f\u56fe\u8868\u548c\u4ee3\u7801\u63d0\u793a\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5206\u6790\u548c\u4f18\u5316\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u5206\u6790 PHP \u5185\u7f6e\u51fd\u6570 array_merge()<\/strong><\/p>\n<p>\u4f7f\u7528 <strong>PHP Profiling \u5de5\u5177\u5305<\/strong> \u5206\u6790 array_merge() \u51fd\u6570\u7684\u6027\u80fd\uff1a<\/p>\n<pre>ini_set('profiler.enable', 1);\nini_set('profiler.output_dir', '\/tmp');\narray_merge(range(1, 10000), range(1, 10000));<\/pre>\n<p>\u8fd9\u5c06\u5728 <code>\/tmp<\/code> \u76ee\u5f55\u4e2d\u751f\u6210\u4e00\u4e2a <code>profiler-output<\/code> \u6587\u4ef6\uff0c\u5305\u542b\u5206\u6790\u62a5\u544a\u3002\u62a5\u544a\u5c06\u663e\u793a array_merge() \u7684\u6267\u884c\u65f6\u95f4\u548c\u8c03\u7528\u6811\u3002<\/p>\n<p><strong>\u4f18\u5316 array_merge()<\/strong><\/p>\n<p>\u6839\u636e\u5206\u6790\u62a5\u544a\uff0c\u6211\u4eec\u53d1\u73b0 array_merge() \u7684\u6027\u80fd\u74f6\u9888\u5728\u4e8e\u4f7f\u7528\u4e86\u4e00\u6b21\u8fed\u4ee3\u904d\u5386\u7b2c\u4e00\u4e2a\u6570\u7ec4\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 spread \u8bed\u6cd5 (<code>...<\/code>) \u6765\u4f18\u5316\u5b83\uff0c\u5c06\u4e24\u4e2a\u6570\u7ec4\u5408\u5e76\u5728\u4e00\u6b21\u904d\u5386\u4e2d\uff1a<\/p>\n<pre>array_merge(..., range(1, 10000), range(1, 10000));<\/pre>\n<p>\u8fd9\u5c06\u663e\u8457\u63d0\u9ad8 array_merge() \u7684\u6027\u80fd\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u6df1\u5165\u4e86\u89e3\u51fd\u6570\u7684\u8fd0\u884c\uff0c\u627e\u51fa\u6027\u80fd\u74f6\u9888\u5e76\u8fdb\u884c\u4f18\u5316\u3002\u8fd9\u4e9b\u5de5\u5177\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u8bc6\u522b\u95ee\u9898\u5e76\u63d0\u9ad8\u4ee3\u7801\u7684\u6548\u7387\uff0c\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u6700\u4f73\u6027\u80fd\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f \u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587\u300aphp\u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u5982\u4f55\u8fdb\u884c\u5206\u6790\uff1f\u300b\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01 PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\u4ecb\u7ecd\uff1a\u52a9\u4f60\u6df1\u5165\u63a2\u7a76\u51fd\u6570\u8fd0\u884c \u5f15\u8a00 \u4f5c\u4e3a PHP \u5f00\u53d1\u4eba\u5458\uff0c\u4e3a\u4e86\u4f18\u5316\u4ee3\u7801\u6027\u80fd\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5206\u6790\u51fd\u6570\u7684\u6267\u884c\u60c5\u51b5\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u4e2a\u5b9e\u7528\u7684 PHP \u51fd\u6570\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u5e2e\u52a9\u4f60\u6df1\u5165\u63a2\u7a76\u51fd\u6570\u7684\u8fd0\u884c\uff0c\u627e\u51fa\u6027\u80fd\u74f6\u9888\u5e76\u8fdb\u884c\u4f18\u5316\u3002 \u5de5\u5177\u4ecb\u7ecd 1. PHP Profiling \u5de5\u5177\u5305 PHP Profiling \u5de5\u5177\u5305\u662f PHP \u5185\u7f6e\u7684\u4e00\u4e2a\u5f3a\u5927\u5de5\u5177\uff0c\u53ef\u4ee5\u751f\u6210\u51fd\u6570\u8c03\u7528\u548c\u8d44\u6e90\u6d88\u8017\u7684\u8be6\u7ec6\u5206\u6790\u62a5\u544a\u3002\u5b83\u662f\u5185\u7f6e\u4e8e PHP \u6838\u5fc3\u4e2d\u7684\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u5b89\u88c5\u989d\u5916\u7684\u6269\u5c55\u3002 2. Xdebug Xdebug \u662f\u4e00\u4e2a\u6d41\u884c\u7684 PHP \u8c03\u8bd5\u548c\u5206\u6790\u6269\u5c55\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5305\u62ec\u6027\u80fd\u5206\u6790\u3002\u5b83\u53ef\u4ee5\u8ddf\u8e2a\u51fd\u6570\u8c03\u7528\u5e76\u663e\u793a\u6bcf\u4e2a\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u548c\u5185\u5b58\u6d88\u8017\u3002 3. Blackfire.io Blackfire.io \u662f\u4e00\u4e2a\u57fa\u4e8e\u4e91\u7684 PHP \u6027\u80fd\u5206\u6790\u5e73\u53f0\uff0c\u63d0\u4f9b\u4ea4\u4e92\u5f0f\u56fe\u8868\u548c\u4ee3\u7801\u63d0\u793a\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5206\u6790\u548c\u4f18\u5316\u4ee3\u7801\u3002 \u5b9e\u6218\u6848\u4f8b \u5206\u6790 PHP \u5185\u7f6e\u51fd\u6570 array_merge() \u4f7f\u7528 PHP Profiling \u5de5\u5177\u5305 \u5206\u6790 array_merge() \u51fd\u6570\u7684\u6027\u80fd\uff1a ini_set(&#8216;profiler.enable&#8217;, 1); ini_set(&#8216;profiler.output_dir&#8217;, &#8216;\/tmp&#8217;); array_merge(range(1, 10000), range(1, 10000)); \u8fd9\u5c06\u5728 [&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-47339","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47339","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=47339"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47339\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}