{"id":202463,"date":"2025-05-13T14:48:04","date_gmt":"2025-05-13T06:48:04","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202463\/"},"modified":"2025-05-13T14:48:04","modified_gmt":"2025-05-13T06:48:04","slug":"%e5%a6%82%e4%bd%95%e5%af%b9-php-%e5%87%bd%e6%95%b0%e6%89%a9%e5%b1%95%e8%bf%9b%e8%a1%8c%e8%b0%83%e8%af%95%e5%92%8c%e6%8e%92%e9%94%99%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202463\/","title":{"rendered":"\u5982\u4f55\u5bf9 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c\u8c03\u8bd5\u548c\u6392\u9519\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u5bf9 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c\u8c03\u8bd5\u548c\u6392\u9519\uff1f<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5bf9 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c\u8c03\u8bd5\u548c\u6392\u9519\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>\u5982\u4f55\u8c03\u8bd5 PHP \u51fd\u6570\u6269\u5c55\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u8c03\u8bd5 PHP \u51fd\u6570\u6269\u5c55\uff1aXdebug\uff1a\u7528\u4e8e\u51fd\u6570\u8ffd\u8e2a\u3001\u5806\u6808\u8ffd\u8e2a\u3001\u53d8\u91cf\u68c0\u67e5\u3002PHP \u8c03\u8bd5\u52a9\u624b\uff1a\u4f7f\u7528 var_dump()\u3001print_r()\u3001debug_backtrace() \u7b49\u51fd\u6570\u3002PHP \u65e5\u5fd7\uff1a\u4f7f\u7528 error_log() \u8bb0\u5f55\u8c03\u8bd5\u6d88\u606f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729835976671b33c8bfe0c.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u5bf9 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c\u8c03\u8bd5\u548c\u6392\u9519<\/strong><\/p>\n<p>PHP \u51fd\u6570\u6269\u5c55\u662f\u6269\u5927 PHP \u6838\u5fc3\u529f\u80fd\u7684\u5f3a\u5927\u5de5\u5177\u3002\u7136\u800c\uff0c\u5728\u5f00\u53d1\u548c\u90e8\u7f72\u6269\u5c55\u65f6\uff0c\u8c03\u8bd5\u548c\u6392\u9519\u53ef\u80fd\u9887\u5177\u6311\u6218\u6027\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u5982\u4f55\u6709\u6548\u5730\u8c03\u8bd5\u548c\u6392\u9519 PHP \u51fd\u6570\u6269\u5c55\u3002<\/p>\n<p><strong>1. \u4f7f\u7528 Xdebug<\/strong><\/p>\n<p>Xdebug \u662f\u4e00\u4e2a PHP \u8c03\u8bd5\u6269\u5c55\uff0c\u63d0\u4f9b\u5e7f\u6cdb\u7684\u529f\u80fd\uff0c\u5305\u62ec\u51fd\u6570\u8ffd\u8e2a\u3001\u5806\u6808\u8ffd\u8e2a\u548c\u53d8\u91cf\u68c0\u67e5\u3002\u8981\u4f7f\u7528 Xdebug \u8c03\u8bd5\u6269\u5c55\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u5b89\u88c5 Xdebug \u6269\u5c55\u3002<\/li>\n<li>\u5728 <code>php.ini<\/code> \u4e2d\u914d\u7f6e Xdebug \u8bbe\u7f6e\u3002<\/li>\n<li>\u4f7f\u7528 Xdebug \u5ba2\u6237\u7aef\u8fde\u63a5\u5230\u60a8\u7684 PHP \u73af\u5883\u3002<\/li>\n<li>\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u65ad\u70b9\u5e76\u5728\u5ba2\u6237\u7aef\u4e2d\u6b65\u9aa4\u6267\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u5728\u60a8\u7684\u6269\u5c55\u6587\u4ef6\u4e2d\uff1a\n\/\/ \u6dfb\u52a0 Xdebug \u8bb0\u5f55\u4ee5\u8f93\u51fa\u8f68\u8ff9\nfunction debug_trace($msg) {\n  xdebug_log(\"[$i] $msg\");\n  $i++;\n}<\/pre>\n<p><strong>2. \u4f7f\u7528 PHP \u8c03\u8bd5\u52a9\u624b<\/strong><\/p>\n<p>PHP \u8c03\u8bd5\u52a9\u624b\u63d0\u4f9b\u4e86\u4e00\u7ec4\u5185\u7f6e\u51fd\u6570\uff0c\u7528\u4e8e\u8c03\u8bd5\u548c\u6392\u9519\u3002\u8fd9\u4e9b\u51fd\u6570\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>var_dump()<\/code>: \u8f93\u51fa\u53d8\u91cf\u7684\u503c\u548c\u7c7b\u578b\u3002<\/li>\n<li><code>print_r()<\/code>: \u4ee5\u4eba\u7c7b\u53ef\u8bfb\u7684\u683c\u5f0f\u8f93\u51fa\u53d8\u91cf\u7684\u503c\u548c\u7c7b\u578b\u3002<\/li>\n<li><code>debug_backtrace()<\/code>: \u8f93\u51fa\u8c03\u7528\u5806\u6808\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u4f7f\u7528 var_dump() \u8f93\u51fa\u53d8\u91cf\u503c\nvar_dump($variable);<\/pre>\n<p><strong>3. \u4f7f\u7528 PHP \u65e5\u5fd7<\/strong><\/p>\n<p>PHP \u65e5\u5fd7\u63d0\u4f9b\u4e86\u8bb0\u5f55\u8c03\u8bd5\u4fe1\u606f\u7684\u4fbf\u6377\u65b9\u5f0f\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u914d\u7f6e PHP \u65e5\u5fd7\uff1a<\/p>\n<ul>\n<li>\u5728 <code>php.ini<\/code> \u4e2d\u914d\u7f6e\u65e5\u5fd7\u8bbe\u7f6e\u3002<\/li>\n<li>\u4f7f\u7528 <code>error_log()<\/code> \u51fd\u6570\u8bb0\u5f55\u65e5\u5fd7\u6d88\u606f\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u8bb0\u5f55\u8c03\u8bd5\u6d88\u606f\u5230\u65e5\u5fd7\u6587\u4ef6\nerror_log(\"[$i] $msg\", 3, \"my_error_log.txt\");<\/pre>\n<p><strong>4. \u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u60c5\u666f\uff1a<\/strong>\u60a8\u6b63\u5728\u5f00\u53d1\u4e00\u4e2a\u51fd\u6570\u6269\u5c55\uff0c\u8be5\u6269\u5c55\u5e94\u5c06\u4e00\u7ec4\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u4f46\u6269\u5c55\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<p><strong>\u8c03\u8bd5\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\u4f7f\u7528 Xdebug \u8bbe\u7f6e\u65ad\u70b9\u4ee5\u8ffd\u8e2a\u51fd\u6570\u6267\u884c\u3002<\/li>\n<li>\u5728\u51fd\u6570\u4e2d\u6dfb\u52a0 Xdebug \u8bb0\u5f55\u4ee5\u8f93\u51fa\u8c03\u8bd5\u6d88\u606f\u3002<\/li>\n<li>\u68c0\u67e5 PHP \u65e5\u5fd7\u4e2d\u7684\u9519\u8bef\u6d88\u606f\u3002<\/li>\n<li>\u4f7f\u7528 <code>var_dump()<\/code> \u67e5\u770b\u51fd\u6570\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002<\/li>\n<li>\u4f7f\u7528 <code>error_log()<\/code> \u8bb0\u5f55\u8c03\u8bd5\u6d88\u606f\uff0c\u4ee5\u8be6\u7ec6\u4e86\u89e3\u51fd\u6570\u7684\u884c\u4e3a\u3002<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u8bd5\u548c\u6392\u9519 PHP \u51fd\u6570\u6269\u5c55\uff0c\u786e\u4fdd\u5b83\u4eec\u6309\u9884\u671f\u5de5\u4f5c\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u5bf9 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c\u8c03\u8bd5\u548c\u6392\u9519\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\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5bf9 PHP \u51fd\u6570\u6269\u5c55\u8fdb\u884c\u8c03\u8bd5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202463","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202463"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202463\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}