{"id":48057,"date":"2024-12-02T13:25:50","date_gmt":"2024-12-02T05:25:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48057\/"},"modified":"2024-12-02T13:25:50","modified_gmt":"2024-12-02T05:25:50","slug":"php-%e5%87%bd%e6%95%b0%e5%86%85%e5%ad%98%e6%b3%84%e9%9c%b2%e6%a3%80%e6%b5%8b%e4%b8%8e%e4%bf%ae%e5%a4%8d%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48057\/","title":{"rendered":"PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357<\/h1>\n<p>\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357\u300b<\/span>\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729952967671cfcc7e5a18.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u5185\u5b58\u6cc4\u9732\u662f\u6307\u7531\u4e8e\u7f16\u7a0b\u4e0d\u5f53\u6216\u7f3a\u9677\uff0c\u5bfc\u81f4 PHP \u5e94\u7528\u9a7b\u7559\u5185\u5b58\uff0c\u5373\u4f7f\u7a0b\u5e8f\u4e0d\u518d\u9700\u8981\u5b83\u4eec\u3002\u8fd9\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3001\u670d\u52a1\u5668\u5d29\u6e83\uff0c\u751a\u81f3\u5e94\u7528\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<p><strong>\u5185\u5b58\u6cc4\u9732\u7684\u68c0\u6d4b<\/strong><\/p>\n<p>\u6709\u51e0\u79cd\u68c0\u6d4b PHP \u5185\u5b58\u6cc4\u6f0f\u7684\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 PHP \u5185\u7f6e\u7684 <code>memory_get_usage<\/code> \u548c <code>memory_get_peak_usage<\/code> \u51fd\u6570<\/li>\n<li>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff0c\u4f8b\u5982 <em>PHP Memory Leak Extension<\/em><\/li>\n<li>\u4f7f\u7528 Xdebug \u5185\u5b58\u8c03\u8bd5\u5668<\/li>\n<li>\u5206\u6790\u670d\u52a1\u5668\u65e5\u5fd7\u4e2d\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/li>\n<\/ul>\n<p><strong>\u4fee\u590d\u5185\u5b58\u6cc4\u9732<\/strong><\/p>\n<p>\u5185\u5b58\u6cc4\u9732\u7684\u4fee\u590d\u53d6\u51b3\u4e8e\u5176\u539f\u56e0\u3002\u4e00\u4e9b\u5e38\u89c1\u7684\u4fee\u590d\u65b9\u6cd5\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5f15\u7528\uff1a<\/strong>\u53ea\u5728\u5fc5\u8981\u65f6\u521b\u5efa\u53d8\u91cf\u548c\u5f15\u7528<\/li>\n<li><strong>\u91ca\u653e\u672a\u4f7f\u7528\u8d44\u6e90\uff1a<\/strong>\u5728\u4e0d\u518d\u9700\u8981\u65f6\u91ca\u653e\u6570\u636e\u5e93\u8fde\u63a5\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u5176\u4ed6\u8d44\u6e90<\/li>\n<li><strong>\u4f7f\u7528\u5f31\u5f15\u7528\uff1a<\/strong>\u5982\u679c\u9700\u8981\u4f7f\u7528\u5bf9\u8c61\u4f46\u53c8\u4e0d\u60f3\u521b\u5efa\u5f3a\u5f15\u7528\uff0c\u8bf7\u4f7f\u7528 <code>WeakReference<\/code> \u7c7b<\/li>\n<li><strong>\u4f7f\u7528\u5783\u573e\u6536\u96c6\u5668\uff1a<\/strong>\u5982\u679c\u53ef\u80fd\uff0c\u8bf7\u542f\u7528 PHP \u7684\u5783\u573e\u6536\u96c6\u529f\u80fd<\/li>\n<li><strong>\u67e5\u770b\u6587\u6863\uff1a<\/strong>\u4ed4\u7ec6\u9605\u8bfb PHP \u51fd\u6570\u548c\u7c7b\u7684\u6587\u6863\uff0c\u4e86\u89e3\u5176\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u4e00\u4e2a PHP \u811a\u672c\u91cd\u590d\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5bfc\u81f4\u5185\u5b58\u6cc4\u9732\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u68c0\u67e5\u811a\u672c\u662f\u5426\u5728\u4e0d\u518d\u9700\u8981\u65f6\u6b63\u786e\u5173\u95ed\u8fde\u63a5\uff1a<\/p>\n<pre>&lt;?php\n$db = new mysqli('localhost', 'user', 'password', 'database');\n$result = $db-&gt;query('SELECT * FROM table');\n\/\/\u5173\u95ed\u8fde\u63a5\n$db-&gt;close();\n?&gt;<\/pre>\n<p><strong> conclusion<\/strong><\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357 \u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300aPHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357\u300b\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~ PHP \u51fd\u6570\u5185\u5b58\u6cc4\u9732\u68c0\u6d4b\u4e0e\u4fee\u590d\u6307\u5357 \u5f15\u8a00 \u5185\u5b58\u6cc4\u9732\u662f\u6307\u7531\u4e8e\u7f16\u7a0b\u4e0d\u5f53\u6216\u7f3a\u9677\uff0c\u5bfc\u81f4 PHP \u5e94\u7528\u9a7b\u7559\u5185\u5b58\uff0c\u5373\u4f7f\u7a0b\u5e8f\u4e0d\u518d\u9700\u8981\u5b83\u4eec\u3002\u8fd9\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3001\u670d\u52a1\u5668\u5d29\u6e83\uff0c\u751a\u81f3\u5e94\u7528\u7a0b\u5e8f\u5d29\u6e83\u3002 \u5185\u5b58\u6cc4\u9732\u7684\u68c0\u6d4b \u6709\u51e0\u79cd\u68c0\u6d4b PHP \u5185\u5b58\u6cc4\u6f0f\u7684\u65b9\u6cd5\uff1a \u4f7f\u7528 PHP \u5185\u7f6e\u7684 memory_get_usage \u548c memory_get_peak_usage \u51fd\u6570 \u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff0c\u4f8b\u5982 PHP Memory Leak Extension \u4f7f\u7528 Xdebug \u5185\u5b58\u8c03\u8bd5\u5668 \u5206\u6790\u670d\u52a1\u5668\u65e5\u5fd7\u4e2d\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5 \u4fee\u590d\u5185\u5b58\u6cc4\u9732 \u5185\u5b58\u6cc4\u9732\u7684\u4fee\u590d\u53d6\u51b3\u4e8e\u5176\u539f\u56e0\u3002\u4e00\u4e9b\u5e38\u89c1\u7684\u4fee\u590d\u65b9\u6cd5\u5305\u62ec\uff1a \u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5f15\u7528\uff1a\u53ea\u5728\u5fc5\u8981\u65f6\u521b\u5efa\u53d8\u91cf\u548c\u5f15\u7528 \u91ca\u653e\u672a\u4f7f\u7528\u8d44\u6e90\uff1a\u5728\u4e0d\u518d\u9700\u8981\u65f6\u91ca\u653e\u6570\u636e\u5e93\u8fde\u63a5\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u5176\u4ed6\u8d44\u6e90 \u4f7f\u7528\u5f31\u5f15\u7528\uff1a\u5982\u679c\u9700\u8981\u4f7f\u7528\u5bf9\u8c61\u4f46\u53c8\u4e0d\u60f3\u521b\u5efa\u5f3a\u5f15\u7528\uff0c\u8bf7\u4f7f\u7528 WeakReference \u7c7b \u4f7f\u7528\u5783\u573e\u6536\u96c6\u5668\uff1a\u5982\u679c\u53ef\u80fd\uff0c\u8bf7\u542f\u7528 PHP \u7684\u5783\u573e\u6536\u96c6\u529f\u80fd \u67e5\u770b\u6587\u6863\uff1a\u4ed4\u7ec6\u9605\u8bfb PHP \u51fd\u6570\u548c\u7c7b\u7684\u6587\u6863\uff0c\u4e86\u89e3\u5176\u5185\u5b58\u4f7f\u7528\u60c5\u51b5 \u5b9e\u6218\u6848\u4f8b \u95ee\u9898\uff1a \u4e00\u4e2a PHP \u811a\u672c\u91cd\u590d\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5bfc\u81f4\u5185\u5b58\u6cc4\u9732\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u68c0\u67e5\u811a\u672c\u662f\u5426\u5728\u4e0d\u518d\u9700\u8981\u65f6\u6b63\u786e\u5173\u95ed\u8fde\u63a5\uff1a &lt;?php $db = new mysqli(&#8216;localhost&#8217;, [&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-48057","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48057","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=48057"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48057\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}