{"id":48384,"date":"2024-12-02T09:04:22","date_gmt":"2024-12-02T01:04:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48384\/"},"modified":"2024-12-02T09:04:22","modified_gmt":"2024-12-02T01:04:22","slug":"php%e5%87%bd%e6%95%b0%e7%ae%97%e6%b3%95%e4%bc%98%e5%8c%96%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%bc%82%e6%ad%a5%e7%bc%96%e7%a8%8b%e4%b8%8e%e5%b9%b6%e5%8f%91%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48384\/","title":{"rendered":"php\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316<\/h1>\n<p>\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p>\u901a\u8fc7\u5f02\u6b65\u7f16\u7a0b\u548c\u5e76\u53d1\u4f18\u5316\uff0c\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8 PHP \u51fd\u6570\u7684\u6267\u884c\u901f\u5ea6\u3002\u5f02\u6b65\u7f16\u7a0b\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6267\u884c\uff0c\u800c\u5e76\u53d1\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\u3002\u5b9e\u6218\u6848\u4f8b\u8868\u660e\uff0c\u901a\u8fc7\u4f7f\u7528\u5f02\u6b65\u7f16\u7a0b\u4f18\u5316\u8d2d\u7269\u8f66\u8ba1\u7b97\u903b\u8f91\uff0c\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u6267\u884c\u65f6\u95f4\u3002\u5176\u4ed6\u4f18\u5316\u7b56\u7565\u5305\u62ec\u7f13\u5b58\u7ed3\u679c\u3001\u4f7f\u7528\u9002\u5408\u7684\u6570\u636e\u7ed3\u6784\u3001\u6267\u884c\u6301\u7eed\u6027\u80fd\u5206\u6790\u4ee5\u53ca\u4f7f\u7528\u4f18\u5316\u5de5\u5177\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730021014671e0696b8918.jpg\" class=\"aligncenter\" title=\"php\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316\u63d2\u56fe\" alt=\"php\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u7b97\u6cd5\u4f18\u5316\u5bf9\u4e8e\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u5f02\u6b65\u7f16\u7a0b\u548c\u5e76\u53d1\u6280\u672f\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u51fd\u6570\u7684\u6267\u884c\u901f\u5ea6\u3002<\/p>\n<p><strong>\u5f02\u6b65\u7f16\u7a0b<\/strong><\/p>\n<p>\u5f02\u6b65\u7f16\u7a0b\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u3002\u8fd9\u5bf9\u4e8e\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u4efb\u52a1\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982 I\/O \u64cd\u4f5c\u6216 API \u8c03\u7528\u3002<\/p>\n<p><code>\u4f8b 1<\/code> \u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 Amp (\u4e00\u4e2a PHP \u5f02\u6b65\u7f16\u7a0b\u5e93) \u6267\u884c\u5f02\u6b65 HTTP \u8bf7\u6c42\uff1a<\/p>\n<pre>use Amp\\GuzzleHttp\\Client;\n\n$response = yield (new Client)-&gt;get('https:\/\/example.com');<\/pre>\n<p><strong>\u5e76\u53d1\u4f18\u5316<\/strong><\/p>\n<p>\u5e76\u53d1\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\u6216\u7ebf\u7a0b\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u8d44\u6e90\u5229\u7528\u7387\uff0c\u5e76\u51cf\u5c11\u603b\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<p><code>\u4f8b 2<\/code> \u5c55\u793a\u4e86\u4f7f\u7528 <code>exec() PHP<\/code> \u51fd\u6570\u5e76\u884c\u6267\u884c\u4e24\u4e2a\u547d\u4ee4\uff1a<\/p>\n<pre>$command1 = 'ls -l';\n$command2 = 'free -m';\n\nexec([$command1, $command2], $output);<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5728\u4e00\u4e2a\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u4e2d\uff0c\u8d2d\u7269\u8f66\u8ba1\u7b97\u903b\u8f91\u9700\u8981\u5927\u91cf\u7684 I\/O \u64cd\u4f5c\u3002\u901a\u8fc7\u4f7f\u7528\u5f02\u6b65\u7f16\u7a0b\uff0c\u53ef\u4ee5\u5e76\u884c\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\uff0c\u4ece\u800c\u663e\u8457\u51cf\u5c11\u8d2d\u7269\u8f66\u8ba1\u7b97\u65f6\u95f4\u3002<\/p>\n<p><strong>\u4f18\u5316\u7b56\u7565<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u51fd\u6570\u7b97\u6cd5\u7684\u989d\u5916\u7b56\u7565\uff1a<\/p>\n<ul>\n<li>\u7f13\u5b58\u7ed3\u679c\u4ee5\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u3002<\/li>\n<li>\u4f7f\u7528\u6570\u636e\u7ed3\u6784\uff08\u5982\u54c8\u5e0c\u8868\u6216\u6811\uff09\u6765\u4f18\u5316\u67e5\u627e\u64cd\u4f5c\u3002<\/li>\n<li>\u6267\u884c\u6301\u7eed\u6027\u80fd\u5206\u6790\u4ee5\u8bc6\u522b\u74f6\u9888\u3002<\/li>\n<li>\u4f7f\u7528\u7b2c\u4e09\u65b9\u4f18\u5316\u5de5\u5177\uff0c\u5982 PHPStan \u6216 Psalm\u3002<\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aphp\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316 \u4f60\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587\u300aphp\u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01 \u901a\u8fc7\u5f02\u6b65\u7f16\u7a0b\u548c\u5e76\u53d1\u4f18\u5316\uff0c\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8 PHP \u51fd\u6570\u7684\u6267\u884c\u901f\u5ea6\u3002\u5f02\u6b65\u7f16\u7a0b\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6267\u884c\uff0c\u800c\u5e76\u53d1\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\u3002\u5b9e\u6218\u6848\u4f8b\u8868\u660e\uff0c\u901a\u8fc7\u4f7f\u7528\u5f02\u6b65\u7f16\u7a0b\u4f18\u5316\u8d2d\u7269\u8f66\u8ba1\u7b97\u903b\u8f91\uff0c\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u6267\u884c\u65f6\u95f4\u3002\u5176\u4ed6\u4f18\u5316\u7b56\u7565\u5305\u62ec\u7f13\u5b58\u7ed3\u679c\u3001\u4f7f\u7528\u9002\u5408\u7684\u6570\u636e\u7ed3\u6784\u3001\u6267\u884c\u6301\u7eed\u6027\u80fd\u5206\u6790\u4ee5\u53ca\u4f7f\u7528\u4f18\u5316\u5de5\u5177\u3002 PHP \u51fd\u6570\u7b97\u6cd5\u4f18\u5316\u6280\u5de7\uff1a\u5f02\u6b65\u7f16\u7a0b\u4e0e\u5e76\u53d1\u4f18\u5316 \u5f15\u8a00 \u5728 PHP \u4e2d\uff0c\u7b97\u6cd5\u4f18\u5316\u5bf9\u4e8e\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u5f02\u6b65\u7f16\u7a0b\u548c\u5e76\u53d1\u6280\u672f\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u51fd\u6570\u7684\u6267\u884c\u901f\u5ea6\u3002 \u5f02\u6b65\u7f16\u7a0b \u5f02\u6b65\u7f16\u7a0b\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u3002\u8fd9\u5bf9\u4e8e\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u4efb\u52a1\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982 I\/O \u64cd\u4f5c\u6216 API \u8c03\u7528\u3002 \u4f8b 1 \u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 Amp (\u4e00\u4e2a PHP \u5f02\u6b65\u7f16\u7a0b\u5e93) \u6267\u884c\u5f02\u6b65 HTTP \u8bf7\u6c42\uff1a use Amp\\GuzzleHttp\\Client; $response = yield (new Client)-&gt;get(&#8216;https:\/\/example.com&#8217;); \u5e76\u53d1\u4f18\u5316 \u5e76\u53d1\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\u6216\u7ebf\u7a0b\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u8d44\u6e90\u5229\u7528\u7387\uff0c\u5e76\u51cf\u5c11\u603b\u6267\u884c\u65f6\u95f4\u3002 \u4f8b 2 \u5c55\u793a\u4e86\u4f7f\u7528 exec() PHP \u51fd\u6570\u5e76\u884c\u6267\u884c\u4e24\u4e2a\u547d\u4ee4\uff1a $command1 = &#8216;ls -l&#8217;; $command2 = &#8216;free -m&#8217;; exec([$command1, $command2], $output); \u5b9e\u6218\u6848\u4f8b \u5728\u4e00\u4e2a\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u4e2d\uff0c\u8d2d\u7269\u8f66\u8ba1\u7b97\u903b\u8f91\u9700\u8981\u5927\u91cf\u7684 [&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-48384","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48384","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=48384"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48384\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}