{"id":200543,"date":"2025-05-06T08:58:21","date_gmt":"2025-05-06T00:58:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200543\/"},"modified":"2025-05-06T08:58:21","modified_gmt":"2025-05-06T00:58:21","slug":"php-%e8%84%9a%e6%9c%ac%e5%87%ba%e7%8e%b0-mysqli_query-broken-pipe-%e9%94%99%e8%af%af%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e8%bf%9e%e6%8e%a5%e4%b8%ad%e6%96%ad%e9%97%ae%e9%a2%98%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200543\/","title":{"rendered":"PHP \u811a\u672c\u51fa\u73b0 mysqli_query() Broken Pipe \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\u8fde\u63a5\u4e2d\u65ad\u95ee\u9898\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u811a\u672c\u51fa\u73b0 mysqli_query() Broken Pipe \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\u8fde\u63a5\u4e2d\u65ad\u95ee\u9898\uff1f<\/h1>\n<p>\u4e3b\u673a\u5b9d\u8d1d\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241108\/1731028905672d67a902ae2.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>php \u811a\u672c\u51fa\u73b0 mysqli_query() broken pipe \u9519\u8bef\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u4f60\u5728\u4f7f\u7528 php \u7f16\u5199\u5e38\u9a7b\u5185\u5b58\u961f\u5217\u5904\u7406\u811a\u672c\u65f6\u9047\u5230\u4e86 mysqli_query() \u9519\u8bef\uff0c\u63d0\u793a broken pipe\u3002\u8fd9\u8868\u660e\u670d\u52a1\u5668\u4e0e\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u8fde\u63a5\u4e2d\u65ad\u3002<\/p>\n<p>\u9020\u6210\u6b64\u9519\u8bef\u7684\u539f\u56e0\u53ef\u80fd\u662f\u670d\u52a1\u5668\u7aef\u5173\u95ed\u4e86\u8fde\u63a5\uff0c\u56e0\u4e3a\u811a\u672c\u957f\u65f6\u95f4\u5904\u4e8e\u65e0\u64cd\u4f5c\u72b6\u6001\u3002\u867d\u7136\u4f60\u5df2\u8c03\u6574 max_allowed_packet \u53c2\u6570\uff0c\u4f46\u8fd9\u4f3c\u4e4e\u5e76\u4e0d\u662f\u95ee\u9898\u7684\u6839\u6e90\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5\u5e76\u8c03\u6574 wait_timeout \u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p>\u767b\u5f55 mysql \u670d\u52a1\u5668\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 wait_timeout \u53c2\u6570\u7684\u5f53\u524d\u8bbe\u7f6e\uff1a<\/p>\n<pre>show variables like 'wait_timeout';<\/pre>\n<\/li>\n<li>\u5c06 wait_timeout \u503c\u589e\u52a0\u5230\u4e00\u4e2a\u66f4\u5408\u9002\u7684\u65f6\u95f4\uff0c\u4f8b\u5982 600 \u79d2\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u8fde\u63a5\u65ad\u5f00\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p>\u5728\u4f60\u7684 php \u811a\u672c\u4e2d\uff0c\u6dfb\u52a0\u4ee3\u7801\u6765\u5904\u7406\u8fde\u63a5\u65ad\u5f00\uff1a<\/p>\n<pre>if (!mysqli_ping($conn)) {\n    \/\/ \u65ad\u5f00\u8fde\u63a5\n    mysqli_close($conn);\n\n    \/\/ \u91cd\u65b0\u8fde\u63a5\n    $conn = mysqli_connect($host, $user, $password, $database);\n}<\/pre>\n<p><strong>\u8bf7\u6ce8\u610f\uff1a<\/strong>\u66ff\u6362 $host\u3001$user\u3001$password \u548c $database \u53d8\u91cf\u4e3a\u4f60\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5176\u4ed6\u5efa\u8bae\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u6570\u636e\u5e93\u670d\u52a1\u5668\u548c php \u811a\u672c\u8fd0\u884c\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u3002<\/li>\n<li>\u68c0\u67e5\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u5b58\u5728\u95ee\u9898\u3002<\/li>\n<li>\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684 mysql \u5ba2\u6237\u7aef\uff08\u4f8b\u5982 mysql \u547d\u4ee4\u884c\u5de5\u5177\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u8c03\u6574\u8fd9\u4e9b\u8bbe\u7f6e\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u907f\u514d broken pipe \u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPHP \u811a\u672c\u51fa\u73b0 mysqli_query() Broken Pipe \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3\u8fde\u63a5\u4e2d\u65ad\u95ee\u9898\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u811a\u672c\u51fa\u73b0 mysqli_&#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":[101],"tags":[],"class_list":["post-200543","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200543","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=200543"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200543\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}