{"id":23704,"date":"2024-11-21T14:03:10","date_gmt":"2024-11-21T06:03:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23704\/"},"modified":"2024-11-21T14:03:10","modified_gmt":"2024-11-21T06:03:10","slug":"%e5%9c%a8thinkphp6%e4%b8%ad%e4%bd%bf%e7%94%a8xdebug%e8%b0%83%e8%af%95%e6%8a%80%e6%9c%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23704\/","title":{"rendered":"\u5728ThinkPHP6\u4e2d\u4f7f\u7528Xdebug\u8c03\u8bd5\u6280\u672f"},"content":{"rendered":"<p>6\u662f\u4e00\u4e2a\u6d41\u884c\u7684php\u6846\u67b6\uff0c\u5b83\u4f7f\u7528\u4e86\u591a\u79cd\u6280\u672f\u8ba9\u5f00\u53d1\u53d8\u5f97\u66f4\u52a0\u4fbf\u5229\u3002\u5176\u4e2d\u4e00\u4e2a\u6280\u672f\u662f\u8c03\u8bd5\u5de5\u5177\uff0c\u5982xdebug\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5982\u4f55\u5728thinkphp6\u4e2d\u4f7f\u7528xdebug\u8fdb\u884c\u8c03\u8bd5\u3002<\/p>\n<p>\u5b89\u88c5\u4e0e\u914d\u7f6eXdebug<\/p>\n<p>\u5728\u5f00\u59cb\u4f7f\u7528Xdebug\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u548c\u542f\u7528\u5b83\u3002\u5728php.ini\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre>[xdebug]\nzend_extension = xdebug.so\nxdebug.remote_enable = 1\nxdebug.remote_autostart = 1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0czend_extension\u662fXdebug\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u53ef\u4ee5\u5728phpinfo()\u4e2d\u67e5\u627e\u3002remote_enable\u548cremote_autostart\u7528\u4e8e\u542f\u7528Xdebug\u8fdc\u7a0b\u8c03\u8bd5\uff0c\u4e5f\u53ef\u4ee5\u5728\u6b64\u4fee\u6539\u8c03\u8bd5\u7aef\u53e3\u3001IP\u5730\u5740\u7b49\u76f8\u5173\u914d\u7f6e\u3002<\/p>\n<p>\u542f\u52a8Xdebug<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5728\u8bbe\u7f6e\u597dXdebug\u7684\u914d\u7f6e\u540e\uff0c\u53ef\u4ee5\u542f\u52a8\u5b83\u3002\u6709\u4e24\u79cd\u542f\u52a8\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>\u4f7f\u7528PHPStorm\u914d\u7f6e\uff1a\u5728PHPStorm\u4e2d\uff0c\u9700\u8981\u9009\u62e9\u201cEdit Configurations\u201d&gt;\u201cPHP Remote Debug\u201d\uff0c\u5e76\u8bbe\u7f6e\u597dXdebug\u914d\u7f6e\u9879\uff0c\u5982\u7aef\u53e3\u53f7\u548c\u670d\u52a1\u5668IP\u7b49\u3002<\/li>\n<li>\u4f7f\u7528\u547d\u4ee4\u884c\u542f\u52a8\uff1a\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u547d\u4ee4php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 .\/your_script.php\u5373\u53ef\u542f\u52a8Xdebug\u8c03\u8bd5\u3002<\/li>\n<\/ol>\n<p>\u8c03\u8bd5\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u542f\u52a8Xdebug\u4ee5\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u8c03\u8bd5\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002\u4e00\u79cd\u8c03\u8bd5\u65b9\u5f0f\u662f\u6dfb\u52a0\u65ad\u70b9\u3002\u5728ThinkPHP6\u4e2d\uff0c\u53ef\u4ee5\u5728\u63a7\u5236\u5668\u4ee3\u7801\u4e2d\u6dfb\u52a0\u65ad\u70b9\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5c55\u793a\u5728\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0\u65ad\u70b9\uff0c\u7528\u4e8e\u8c03\u8bd5UserController\uff1a<\/p>\n<pre>appcontrollerUserController.php\n\n&lt;?php declare(strict_types=1);\n\nnamespace appcontroller;\n\nuse appBaseController;\nuse appmodelUser as UserModel;\n\nclass UserController extends BaseController\n{\n    public function read($id)\n    {\n        $user = UserModel::find($id);\n\n        return json($user);\n    }\n\n    public function index()\n    {\n        $users = UserModel::select();\n\n        return json($users);\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u53ef\u4ee5\u5c06\u65ad\u70b9\u6dfb\u52a0\u5728$user = UserModel::find($id);\u8fd9\u884c\u4ee3\u7801\u4e0a\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u5230\u8fd9\u4e00\u884c\u65f6\uff0cXdebug\u4f1a\u6682\u505c\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\uff0c\u6253\u5f00\u8c03\u8bd5\u5668\u5e76\u5141\u8bb8\u4f60\u67e5\u770b\u53d8\u91cf\u7684\u503c\u3001\u4ee3\u7801\u6267\u884c\u7684\u8def\u5f84\u7b49\u3002<\/p>\n<p>\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u5728\u8c03\u8bd5\u5668\u7a97\u53e3\u4e2d\u63a7\u5236\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\uff0c\u53ef\u4ee5\u5355\u6b65\u8c03\u8bd5\uff08\u4e00\u6b21\u8fd0\u884c\u4e00\u884c\u4ee3\u7801\uff09\uff0c\u4e5f\u53ef\u4ee5\u4ee5\u5176\u4ed6\u65b9\u5f0f\u63a7\u5236\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>Xdebug\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u7279\u522b\u662f\u5728\u8c03\u8bd5\u5927\u578b\u5e94\u7528\u7a0b\u5e8f\u65f6\u3002\u5728\u4f7f\u7528ThinkPHP6\u65f6\uff0c\u4f7f\u7528Xdebug\u8fdb\u884c\u8c03\u8bd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u5e76\u7f29\u77ed\u5f00\u53d1\u5468\u671f\u3002\u638c\u63e1Xdebug\u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u4e86\u89e3\u4ee3\u7801\uff0c\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728ThinkPHP6\u4e2d\u4f7f\u7528Xdebug\u8c03\u8bd5\u6280\u672f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>6\u662f\u4e00\u4e2a\u6d41\u884c\u7684php\u6846\u67b6\uff0c\u5b83\u4f7f\u7528\u4e86\u591a\u79cd\u6280\u672f\u8ba9\u5f00\u53d1\u53d8\u5f97\u66f4\u52a0\u4fbf\u5229\u3002\u5176\u4e2d\u4e00\u4e2a\u6280\u672f\u662f\u8c03\u8bd5\u5de5\u5177\uff0c\u5982xdebug\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5982\u4f55\u5728thinkphp6\u4e2d\u4f7f\u7528xdebug\u8fdb\u884c\u8c03\u8bd5\u3002 \u5b89\u88c5\u4e0e\u914d\u7f6eXdebug \u5728\u5f00\u59cb\u4f7f\u7528Xdebug\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u548c\u542f\u7528\u5b83\u3002\u5728php.ini\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a [xdebug] zend_extension = xdebug.so xdebug.remote_enable = 1 xdebug.remote_autostart = 1 \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0czend_extension\u662fXdebug\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u53ef\u4ee5\u5728phpinfo()\u4e2d\u67e5\u627e\u3002remote_enable\u548cremote_autostart\u7528\u4e8e\u542f\u7528Xdebug\u8fdc\u7a0b\u8c03\u8bd5\uff0c\u4e5f\u53ef\u4ee5\u5728\u6b64\u4fee\u6539\u8c03\u8bd5\u7aef\u53e3\u3001IP\u5730\u5740\u7b49\u76f8\u5173\u914d\u7f6e\u3002 \u542f\u52a8Xdebug \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5728\u8bbe\u7f6e\u597dXdebug\u7684\u914d\u7f6e\u540e\uff0c\u53ef\u4ee5\u542f\u52a8\u5b83\u3002\u6709\u4e24\u79cd\u542f\u52a8\u65b9\u5f0f\uff1a \u4f7f\u7528PHPStorm\u914d\u7f6e\uff1a\u5728PHPStorm\u4e2d\uff0c\u9700\u8981\u9009\u62e9\u201cEdit Configurations\u201d&gt;\u201cPHP Remote Debug\u201d\uff0c\u5e76\u8bbe\u7f6e\u597dXdebug\u914d\u7f6e\u9879\uff0c\u5982\u7aef\u53e3\u53f7\u548c\u670d\u52a1\u5668IP\u7b49\u3002 \u4f7f\u7528\u547d\u4ee4\u884c\u542f\u52a8\uff1a\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u547d\u4ee4php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 .\/your_script.php\u5373\u53ef\u542f\u52a8Xdebug\u8c03\u8bd5\u3002 \u8c03\u8bd5\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f \u542f\u52a8Xdebug\u4ee5\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u8c03\u8bd5\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002\u4e00\u79cd\u8c03\u8bd5\u65b9\u5f0f\u662f\u6dfb\u52a0\u65ad\u70b9\u3002\u5728ThinkPHP6\u4e2d\uff0c\u53ef\u4ee5\u5728\u63a7\u5236\u5668\u4ee3\u7801\u4e2d\u6dfb\u52a0\u65ad\u70b9\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5c55\u793a\u5728\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0\u65ad\u70b9\uff0c\u7528\u4e8e\u8c03\u8bd5UserController\uff1a appcontrollerUserController.php &lt;?php declare(strict_types=1); namespace appcontroller; use appBaseController; use appmodelUser as UserModel; class UserController extends BaseController { public function read($id) { $user = UserModel::find($id); return json($user); } public [&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-23704","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23704","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=23704"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23704\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}