{"id":48012,"date":"2024-12-02T17:05:08","date_gmt":"2024-12-02T09:05:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48012\/"},"modified":"2024-12-02T17:05:08","modified_gmt":"2024-12-02T09:05:08","slug":"php-%e5%87%bd%e6%95%b0%e5%b9%b6%e5%8f%91%e7%bc%96%e7%a8%8b%e7%9a%84%e5%bc%82%e6%ad%a5%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48012\/","title":{"rendered":"PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f<\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p>PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u5305\u62ec\u56de\u8c03\u51fd\u6570\u548c\u534f\u7a0b\u3002\u56de\u8c03\u51fd\u6570\u5728\u53e6\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u540e\u6267\u884c\uff0c\u800c\u534f\u7a0b\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6682\u505c\u548c\u6062\u590d\u6267\u884c\u3002\u4e00\u4e2a\u5b9e\u6218\u6848\u4f8b\u662f\u4f7f\u7528\u534f\u7a0b\u5f02\u6b65\u6267\u884c HTTP \u8bf7\u6c42\uff0c\u5b83\u521b\u5efa\u534f\u7a0b\u6267\u884c\u8bf7\u6c42\uff0c\u800c\u4e3b\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4ee3\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729948892671cecdcca4ac.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f<\/strong><\/p>\n<p>\u5f02\u6b65\u7f16\u7a0b\u662f\u4e00\u79cd\u7f16\u7a0b\u8303\u4f8b\uff0c\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u5e76\u53d1\u6267\u884c\u3002\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u5b9e\u73b0\u5f02\u6b65\u6a21\u5f0f\uff1a<\/p>\n<p><strong>\u56de\u8c03\u51fd\u6570<\/strong><\/p>\n<p>\u56de\u8c03\u51fd\u6570\u662f\u4e00\u79cd\u51fd\u6570\uff0c\u5b83\u5728\u53e6\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u540e\u6267\u884c\u3002\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>register_shutdown_function()<\/code>\u51fd\u6570\u6ce8\u518c\u56de\u8c03\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u5728\u811a\u672c\u6267\u884c\u5b8c\u6210\u540e\u6267\u884c\u3002<\/p>\n<pre>register_shutdown_function(function() {\n  echo \"This function will be executed after the script has finished running.\\n\";\n});<\/pre>\n<p><strong>\u534f\u7a0b<\/strong><\/p>\n<p>\u534f\u7a0b\u662f\u4e00\u79cd\u8f83\u65b0\u7684\u5f02\u6b65\u7f16\u7a0b\u6280\u672f\uff0c\u5b83\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6682\u505c\u548c\u6062\u590d\u6267\u884c\u3002\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>go()<\/code>\u51fd\u6570\u521b\u5efa\u534f\u7a0b\u3002<\/p>\n<pre>go(function() {\n  echo \"This function will be executed concurrently with the main thread.\\n\";\n});<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u534f\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u4e0b\u6267\u884c HTTP \u8bf7\u6c42\u7684\u5b9e\u6218\u6848\u4f8b\uff1a<\/p>\n<pre>use GuzzleHttp\\Client;\n\ngo(function() {\n  $client = new Client();\n  $response = $client-&gt;request('GET', 'https:\/\/example.com');\n  echo $response-&gt;getBody();\n});\n\n\/\/ \u5176\u4ed6\u4ee3\u7801...<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>go()<\/code>\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u534f\u7a0b\uff0c\u5b83\u5c06\u6267\u884c HTTP \u8bf7\u6c42\u3002\u534f\u7a0b\u5c06\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6267\u884c\uff0c\u56e0\u6b64\u5176\u4ed6\u4ee3\u7801\u53ef\u4ee5\u5728\u8bf7\u6c42\u5b8c\u6210\u4e4b\u524d\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u5f02\u6b65,\u5e76\u53d1\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u5305\u62ec\u56de\u8c03\u51fd\u6570\u548c\u534f\u7a0b\u3002\u56de\u8c03\u51fd\u6570\u5728\u53e6\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u540e\u6267\u884c\uff0c\u800c\u534f\u7a0b\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6682\u505c\u548c\u6062\u590d\u6267\u884c\u3002\u4e00\u4e2a\u5b9e\u6218\u6848\u4f8b\u662f\u4f7f\u7528\u534f\u7a0b\u5f02\u6b65\u6267\u884c HTTP \u8bf7\u6c42\uff0c\u5b83\u521b\u5efa\u534f\u7a0b\u6267\u884c\u8bf7\u6c42\uff0c\u800c\u4e3b\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4ee3\u7801\u3002 PHP \u51fd\u6570\u5e76\u53d1\u7f16\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f \u5f02\u6b65\u7f16\u7a0b\u662f\u4e00\u79cd\u7f16\u7a0b\u8303\u4f8b\uff0c\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u5e76\u53d1\u6267\u884c\u3002\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u5b9e\u73b0\u5f02\u6b65\u6a21\u5f0f\uff1a \u56de\u8c03\u51fd\u6570 \u56de\u8c03\u51fd\u6570\u662f\u4e00\u79cd\u51fd\u6570\uff0c\u5b83\u5728\u53e6\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6210\u540e\u6267\u884c\u3002\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528register_shutdown_function()\u51fd\u6570\u6ce8\u518c\u56de\u8c03\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u5728\u811a\u672c\u6267\u884c\u5b8c\u6210\u540e\u6267\u884c\u3002 register_shutdown_function(function() { echo &#8220;This function will be executed after the script has finished running.\\n&#8221;; }); \u534f\u7a0b \u534f\u7a0b\u662f\u4e00\u79cd\u8f83\u65b0\u7684\u5f02\u6b65\u7f16\u7a0b\u6280\u672f\uff0c\u5b83\u5141\u8bb8\u51fd\u6570\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u6682\u505c\u548c\u6062\u590d\u6267\u884c\u3002\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528go()\u51fd\u6570\u521b\u5efa\u534f\u7a0b\u3002 go(function() { echo &#8220;This function will be executed concurrently with the main thread.\\n&#8221;; }); \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u534f\u7a0b\u7684\u5f02\u6b65\u6a21\u5f0f\u4e0b\u6267\u884c HTTP \u8bf7\u6c42\u7684\u5b9e\u6218\u6848\u4f8b\uff1a use [&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-48012","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48012","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=48012"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48012\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}