{"id":25309,"date":"2024-11-21T15:15:38","date_gmt":"2024-11-21T07:15:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25309\/"},"modified":"2024-11-21T15:15:38","modified_gmt":"2024-11-21T07:15:38","slug":"swoole%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25309\/","title":{"rendered":"swoole\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  swoole \u662f\u4e00\u6b3e\u9ad8\u6027\u80fd php web \u6846\u67b6\uff0c\u5176\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a\u5b89\u88c5 swoole \u6269\u5c55\u521b\u5efa swoole http \u670d\u52a1\u5668\u8bbe\u7f6e\u76d1\u542c\u5730\u5740\u548c\u7aef\u53e3\u6ce8\u518c\u5904\u7406\u7a0b\u5e8f\u542f\u52a8\u670d\u52a1\u5668\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040918122797226.jpg\" class=\"aligncenter\" title=\"swoole\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"swoole\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>Swoole\uff1a\u9ad8\u6027\u80fd PHP Web \u6846\u67b6<\/strong><\/p>\n<p>Swoole \u662f\u4e00\u6b3e\u5f02\u6b65\u3001\u975e\u963b\u585e\u7684 PHP Web \u6846\u67b6\uff0c\u4ee5\u5176\u9ad8\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u800c\u95fb\u540d\u3002\u5b83\u91c7\u7528\u534f\u7a0b\u6a21\u578b\uff0c\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u5927\u91cf\uff0c\u5927\u5e45\u63d0\u9ad8 Web \u5e94\u7528\u7684\u541e\u5410\u91cf\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Swoole<\/strong><\/p>\n<p>\u4f7f\u7528 Swoole \u7684\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li> <strong>\u5b89\u88c5 Swoole \u6269\u5c55\uff1a<\/strong>\u4f7f\u7528 pecl install  \u5b89\u88c5 Swoole \u6269\u5c55\u3002<\/li>\n<li> <strong>\u521b\u5efa Swoole HTTP \u670d\u52a1\u5668\uff1a<\/strong>\u4f7f\u7528 SwooleHttpServer \u7c7b\u521b\u5efa\u4e00\u4e2a HTTP \u670d\u52a1\u5668\u5b9e\u4f8b\u3002<\/li>\n<li> <strong>\u8bbe\u7f6e\u76d1\u542c\u5730\u5740\u548c\u7aef\u53e3\uff1a<\/strong>\u4f7f\u7528 set \u65b9\u6cd5\u8bbe\u7f6e\u670d\u52a1\u5668\u76d1\u542c\u7684\u5730\u5740\u548c\u7aef\u53e3\u3002<\/li>\n<li> <strong>\u6ce8\u518c\u5904\u7406\u7a0b\u5e8f\uff1a<\/strong>\u4f7f\u7528 on \u65b9\u6cd5\u6ce8\u518c\u5904\u7406\u8bf7\u6c42\u7684\u56de\u8c03\u51fd\u6570\uff0c\u4f8b\u5982 onReceive \u548c onRequest\u3002<\/li>\n<li> <strong>\u542f\u52a8\u670d\u52a1\u5668\uff1a<\/strong>\u4f7f\u7528 start \u65b9\u6cd5\u542f\u52a8\u670d\u52a1\u5668\u3002<\/li>\n<\/ol>\n<p><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 Swoole HTTP \u670d\u52a1\u5668\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;?php\n\/\/ \u521b\u5efa HTTP \u670d\u52a1\u5668\u5b9e\u4f8b\n$server = new SwooleHttpServer('127.0.0.1', 9501);\n\n\/\/ \u6ce8\u518c\u5904\u7406 \"\u8bf7\u6c42\" \u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570\n$server-&gt;on('request', function (SwooleHttpRequest $request, SwooleHttpResponse $response) {\n    \/\/ \u54cd\u5e94\u8bf7\u6c42\n    $response-&gt;end(\"Hello World!\");\n});\n\n\/\/ \u542f\u52a8\u670d\u52a1\u5668\n$server-&gt;start();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f18\u70b9\u548c\u7f3a\u70b9<\/strong><\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u9ad8\u6027\u80fd\uff1a<\/strong>\u5f02\u6b65\u3001\u975e\u963b\u585e\u7684\u67b6\u6784\uff0c\u53ef\u6781\u5927\u5730\u63d0\u5347\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3002<\/li>\n<li> <strong>\u53ef\u6269\u5c55\u6027\uff1a<\/strong>\u57fa\u4e8e\u534f\u7a0b\u6a21\u578b\uff0c\u53ef\u4ee5\u8f7b\u677e\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\u3002<\/li>\n<li> <strong>\u4f4e\u5185\u5b58\u6d88\u8017\uff1a<\/strong>\u534f\u7a0b\u6a21\u578b\u4e0d\u9700\u8981\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u521b\u5efa\u65b0\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\uff0c\u4ece\u800c\u964d\u4f4e\u5185\u5b58\u5f00\u9500\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u5b66\u4e60\u66f2\u7ebf\uff1a<\/strong>Swoole \u7684\u5f02\u6b65\u7f16\u7a0b\u6a21\u578b\u4e0e\u4f20\u7edf PHP \u7f16\u7a0b\u65b9\u5f0f\u4e0d\u540c\uff0c\u9700\u8981\u4e00\u5b9a\u7684\u5b66\u4e60\u6210\u672c\u3002<\/li>\n<li> <strong>\u8c03\u8bd5\u56f0\u96be\uff1a<\/strong>\u8c03\u8bd5\u534f\u7a0b\u7a0b\u5e8f\u53ef\u80fd\u6bd4\u4f20\u7edf PHP \u4ee3\u7801\u66f4\u56f0\u96be\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>swoole \u662f\u4e00\u6b3e\u9ad8\u6027\u80fd php web \u6846\u67b6\uff0c\u5176\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a\u5b89\u88c5 swoole \u6269\u5c55\u521b\u5efa swoole http \u670d\u52a1\u5668\u8bbe\u7f6e\u76d1\u542c\u5730\u5740\u548c\u7aef\u53e3\u6ce8\u518c\u5904\u7406\u7a0b\u5e8f\u542f\u52a8\u670d\u52a1\u5668 Swoole\uff1a\u9ad8\u6027\u80fd PHP Web \u6846\u67b6 Swoole \u662f\u4e00\u6b3e\u5f02\u6b65\u3001\u975e\u963b\u585e\u7684 PHP Web \u6846\u67b6\uff0c\u4ee5\u5176\u9ad8\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u800c\u95fb\u540d\u3002\u5b83\u91c7\u7528\u534f\u7a0b\u6a21\u578b\uff0c\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u5927\u91cf\uff0c\u5927\u5e45\u63d0\u9ad8 Web \u5e94\u7528\u7684\u541e\u5410\u91cf\u3002 \u5982\u4f55\u4f7f\u7528 Swoole \u4f7f\u7528 Swoole \u7684\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b\uff1a \u5b89\u88c5 Swoole \u6269\u5c55\uff1a\u4f7f\u7528 pecl install \u5b89\u88c5 Swoole \u6269\u5c55\u3002 \u521b\u5efa Swoole HTTP \u670d\u52a1\u5668\uff1a\u4f7f\u7528 SwooleHttpServer \u7c7b\u521b\u5efa\u4e00\u4e2a HTTP \u670d\u52a1\u5668\u5b9e\u4f8b\u3002 \u8bbe\u7f6e\u76d1\u542c\u5730\u5740\u548c\u7aef\u53e3\uff1a\u4f7f\u7528 set \u65b9\u6cd5\u8bbe\u7f6e\u670d\u52a1\u5668\u76d1\u542c\u7684\u5730\u5740\u548c\u7aef\u53e3\u3002 \u6ce8\u518c\u5904\u7406\u7a0b\u5e8f\uff1a\u4f7f\u7528 on \u65b9\u6cd5\u6ce8\u518c\u5904\u7406\u8bf7\u6c42\u7684\u56de\u8c03\u51fd\u6570\uff0c\u4f8b\u5982 onReceive \u548c onRequest\u3002 \u542f\u52a8\u670d\u52a1\u5668\uff1a\u4f7f\u7528 start \u65b9\u6cd5\u542f\u52a8\u670d\u52a1\u5668\u3002 \u4f7f\u7528\u793a\u4f8b [&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-25309","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25309","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=25309"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25309\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}