{"id":47806,"date":"2024-12-02T16:20:35","date_gmt":"2024-12-02T08:20:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47806\/"},"modified":"2024-12-02T16:20:35","modified_gmt":"2024-12-02T08:20:35","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e8%b0%83%e8%af%95%e6%89%a9%e5%b1%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47806\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p>\u5982\u4f55\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\uff1f\u5b89\u88c5Xdebug\u6269\u5c55\uff1b\u5728PHP.ini\u4e2d\u914d\u7f6eXdebug\uff1b\u4f7f\u7528Xdebug\u6216\u547d\u4ee4\u884c\u5de5\u5177\u542f\u52a8\u8c03\u8bd5\u4f1a\u8bdd\uff1b\u8c03\u7528\u6269\u5c55\u51fd\u6570\u5e76\u4f7f\u7528\u8c03\u8bd5\u5668\u68c0\u67e5\u53d8\u91cf\u548c\u7cfb\u7edf\u8c03\u7528\uff1b\u8bbe\u7f6e\u65ad\u70b9\uff0c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u8bc6\u522b\u9519\u8bef\uff1b\u4fee\u590d\u9519\u8bef\uff0c\u5e76\u5728\u9700\u8981\u65f6\u91cd\u590d\u6b65\u9aa4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729937303671cbf979598d.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP\u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f<\/strong><\/p>\n<p><strong>\u6982\u8ff0<\/strong><\/p>\n<p>\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u8bc6\u522b\u5e76\u89e3\u51b3\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Xdebug\u6269\u5c55\u548c\u547d\u4ee4\u884c\u5de5\u5177\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\u3002<\/p>\n<p><strong>\u5148\u51b3\u6761\u4ef6<\/strong><\/p>\n<ul>\n<li>\u5df2\u7f16\u8bd1\u7684PHP\u6269\u5c55\u6587\u4ef6\uff08<code>.so<\/code>\uff09<\/li>\n<li>\u5df2\u5b89\u88c5\u7684Xdebug\u6269\u5c55<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528Xdebug\u8fdb\u884c\u8c03\u8bd5<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u8f91PHP.ini\u6587\u4ef6<\/strong><\/p>\n<p>\u4e3a\u4f60\u7684PHP.ini\u6587\u4ef6\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre>zend_extension=\/path\/to\/xdebug.so\nxdebug.remote_enable=1\nxdebug.remote_port=9000<\/pre>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8\u8c03\u8bd5\u4f1a\u8bdd<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u5e26\u6709Xdebug\u7684PHP CLI\u670d\u52a1\u5668\uff1a<\/p>\n<pre>php -dxdebug.mode=debug -dxdebug.start_with_request=yes<\/pre>\n<\/li>\n<li>\u6216\u8005\u4f7f\u7528IDE\uff08\u5982PhpStorm\uff09\u5e76\u6309\u5feb\u6377\u952eF9\u5f00\u59cb\u8c03\u8bd5\u4f1a\u8bdd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8c03\u7528\u6269\u5c55\u51fd\u6570<\/strong><\/p>\n<p>\u5728\u4f60\u7684PHP\u811a\u672c\u4e2d\uff0c\u8c03\u7528\u8981\u8c03\u8bd5\u7684\u6269\u5c55\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u8c03\u8bd5\u5668<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528Web\u6d4f\u89c8\u5668\u8fde\u63a5\u5230\u8c03\u8bd5\u5668\u7aef\u53e3\uff08\u9ed8\u8ba4\u503c\u4e3a9000\uff09\u3002<\/li>\n<li>\u5728\u8c03\u8bd5\u5668\u4e2d\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u68c0\u67e5\u53d8\u91cf\u548c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u8c03\u8bd5<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528gdb\u8c03\u8bd5\u5668<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8gdb\u8c03\u8bd5\u5668\uff1a<\/p>\n<pre>gdb --args php script.php<\/pre>\n<\/li>\n<li>\u5728\u8c03\u8bd5\u5668\u63d0\u793a\u7b26\u4e0b\u8f93\u5165&#8221;set args\u6269\u5c55\u51fd\u6570&#8221;\u4ee5\u8bbe\u7f6e\u8981\u8c03\u8bd5\u7684\u51fd\u6570\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528strace\u8ddf\u8e2a\u7cfb\u7edf\u8c03\u7528<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8ddf\u8e2aPHP\u6269\u5c55\u51fd\u6570\u7684\u7cfb\u7edf\u8c03\u7528\uff1a<\/p>\n<pre>strace -o trace.txt php script.php<\/pre>\n<\/li>\n<li>\u8f93\u51fa\u6587\u4ef6\u4e2d\u5c06\u5305\u542b\u4e0e\u51fd\u6570\u6267\u884c\u76f8\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u4f60\u7f16\u5199\u4e86\u4e00\u4e2a\u540d\u4e3a<code>my_extension<\/code>\u7684PHP\u6269\u5c55\uff0c\u5b83\u63d0\u4f9b\u4e86<code>my_extension_function()<\/code>\u51fd\u6570\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u5bf9\u5176\u8fdb\u884c\u8c03\u8bd5\uff1a<\/p>\n<ol>\n<li><strong>\u5c06Xdebug\u6dfb\u52a0\u5230\u4f60\u7684PHP.ini\u6587\u4ef6<\/strong><\/li>\n<li><strong>\u4f7f\u7528Xdebug\u542f\u52a8\u4e00\u4e2a\u8c03\u8bd5\u4f1a\u8bdd<\/strong><\/li>\n<li><strong>\u5728\u811a\u672c\u4e2d\u8c03\u7528<code>my_extension_function()<\/code><\/strong><\/li>\n<li><strong>\u5728\u8c03\u8bd5\u5668\u4e2d\u8bbe\u7f6e\u65ad\u70b9\u5e76\u68c0\u67e5\u53d8\u91cf<\/strong><\/li>\n<li><strong>\u8bc6\u522b\u5e76\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef<\/strong><\/li>\n<\/ol>\n<p><strong>\u7ed3\u675f\u8bed<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528Xdebug\u6216\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\uff0c\u4ece\u800c\u52a0\u5feb\u5f00\u53d1\u8fc7\u7a0b\u5e76\u8bc6\u522b\u5e76\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\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\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP \u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u5982\u4f55\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\uff1f\u5b89\u88c5Xdebug\u6269\u5c55\uff1b\u5728PHP.ini\u4e2d\u914d\u7f6eXdebug\uff1b\u4f7f\u7528Xdebug\u6216\u547d\u4ee4\u884c\u5de5\u5177\u542f\u52a8\u8c03\u8bd5\u4f1a\u8bdd\uff1b\u8c03\u7528\u6269\u5c55\u51fd\u6570\u5e76\u4f7f\u7528\u8c03\u8bd5\u5668\u68c0\u67e5\u53d8\u91cf\u548c\u7cfb\u7edf\u8c03\u7528\uff1b\u8bbe\u7f6e\u65ad\u70b9\uff0c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u8bc6\u522b\u9519\u8bef\uff1b\u4fee\u590d\u9519\u8bef\uff0c\u5e76\u5728\u9700\u8981\u65f6\u91cd\u590d\u6b65\u9aa4\u3002 PHP\u51fd\u6570\u5982\u4f55\u8c03\u8bd5\u6269\u5c55\uff1f \u6982\u8ff0 \u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u8bc6\u522b\u5e76\u89e3\u51b3\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Xdebug\u6269\u5c55\u548c\u547d\u4ee4\u884c\u5de5\u5177\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\u3002 \u5148\u51b3\u6761\u4ef6 \u5df2\u7f16\u8bd1\u7684PHP\u6269\u5c55\u6587\u4ef6\uff08.so\uff09 \u5df2\u5b89\u88c5\u7684Xdebug\u6269\u5c55 \u4f7f\u7528Xdebug\u8fdb\u884c\u8c03\u8bd5 \u7f16\u8f91PHP.ini\u6587\u4ef6 \u4e3a\u4f60\u7684PHP.ini\u6587\u4ef6\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a zend_extension=\/path\/to\/xdebug.so xdebug.remote_enable=1 xdebug.remote_port=9000 \u542f\u52a8\u8c03\u8bd5\u4f1a\u8bdd \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u5e26\u6709Xdebug\u7684PHP CLI\u670d\u52a1\u5668\uff1a php -dxdebug.mode=debug -dxdebug.start_with_request=yes \u6216\u8005\u4f7f\u7528IDE\uff08\u5982PhpStorm\uff09\u5e76\u6309\u5feb\u6377\u952eF9\u5f00\u59cb\u8c03\u8bd5\u4f1a\u8bdd\u3002 \u8c03\u7528\u6269\u5c55\u51fd\u6570 \u5728\u4f60\u7684PHP\u811a\u672c\u4e2d\uff0c\u8c03\u7528\u8981\u8c03\u8bd5\u7684\u6269\u5c55\u51fd\u6570\u3002 \u4f7f\u7528\u8c03\u8bd5\u5668 \u4f7f\u7528Web\u6d4f\u89c8\u5668\u8fde\u63a5\u5230\u8c03\u8bd5\u5668\u7aef\u53e3\uff08\u9ed8\u8ba4\u503c\u4e3a9000\uff09\u3002 \u5728\u8c03\u8bd5\u5668\u4e2d\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u68c0\u67e5\u53d8\u91cf\u548c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002 \u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u8c03\u8bd5 \u4f7f\u7528gdb\u8c03\u8bd5\u5668 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8gdb\u8c03\u8bd5\u5668\uff1a gdb &#8211;args php script.php \u5728\u8c03\u8bd5\u5668\u63d0\u793a\u7b26\u4e0b\u8f93\u5165&#8221;set args\u6269\u5c55\u51fd\u6570&#8221;\u4ee5\u8bbe\u7f6e\u8981\u8c03\u8bd5\u7684\u51fd\u6570\u7684\u540d\u79f0\u3002 \u4f7f\u7528strace\u8ddf\u8e2a\u7cfb\u7edf\u8c03\u7528 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8ddf\u8e2aPHP\u6269\u5c55\u51fd\u6570\u7684\u7cfb\u7edf\u8c03\u7528\uff1a strace -o trace.txt php script.php \u8f93\u51fa\u6587\u4ef6\u4e2d\u5c06\u5305\u542b\u4e0e\u51fd\u6570\u6267\u884c\u76f8\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u3002 \u5b9e\u6218\u6848\u4f8b \u5047\u8bbe\u4f60\u7f16\u5199\u4e86\u4e00\u4e2a\u540d\u4e3amy_extension\u7684PHP\u6269\u5c55\uff0c\u5b83\u63d0\u4f9b\u4e86my_extension_function()\u51fd\u6570\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u5bf9\u5176\u8fdb\u884c\u8c03\u8bd5\uff1a \u5c06Xdebug\u6dfb\u52a0\u5230\u4f60\u7684PHP.ini\u6587\u4ef6 \u4f7f\u7528Xdebug\u542f\u52a8\u4e00\u4e2a\u8c03\u8bd5\u4f1a\u8bdd \u5728\u811a\u672c\u4e2d\u8c03\u7528my_extension_function() \u5728\u8c03\u8bd5\u5668\u4e2d\u8bbe\u7f6e\u65ad\u70b9\u5e76\u68c0\u67e5\u53d8\u91cf \u8bc6\u522b\u5e76\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef \u7ed3\u675f\u8bed \u901a\u8fc7\u4f7f\u7528Xdebug\u6216\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u8c03\u8bd5PHP\u6269\u5c55\u51fd\u6570\uff0c\u4ece\u800c\u52a0\u5feb\u5f00\u53d1\u8fc7\u7a0b\u5e76\u8bc6\u522b\u5e76\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002 [&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-47806","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47806","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=47806"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47806\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}