{"id":25320,"date":"2024-11-21T14:43:30","date_gmt":"2024-11-21T06:43:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25320\/"},"modified":"2024-11-21T14:43:30","modified_gmt":"2024-11-21T06:43:30","slug":"swoole%e5%8d%8f%e7%a8%8b%e5%a6%82%e4%bd%95%e5%9c%a8laravel%e4%b8%ad%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25320\/","title":{"rendered":"swoole\u534f\u7a0b\u5982\u4f55\u5728laravel\u4e2d\u4f7f\u7528"},"content":{"rendered":"<blockquote><p>\n  laravel \u4e2d\u4f7f\u7528 swoole \u534f\u7a0b\u53ef\u4ee5\u5e76\u53d1\u5904\u7406\u5927\u91cf\u8bf7\u6c42\uff0c\u4f18\u52bf\u5305\u62ec\uff1a\u5e76\u53d1\u5904\u7406\uff1a\u5141\u8bb8\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u3002\u9ad8\u6027\u80fd\uff1a\u57fa\u4e8e linux epoll \u4e8b\u4ef6\u673a\u5236\uff0c\u9ad8\u6548\u5904\u7406\u8bf7\u6c42\u3002\u4f4e\u8d44\u6e90\u6d88\u8017\uff1a\u6240\u9700\u670d\u52a1\u5668\u8d44\u6e90\u66f4\u5c11\u3002\u6613\u4e8e\u96c6\u6210\uff1a\u4e0e laravel \u6846\u67b6\u65e0\u7f1d\u96c6\u6210\uff0c\u4f7f\u7528\u7b80\u5355\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040918482770014.jpg\" class=\"aligncenter\" title=\"swoole\u534f\u7a0b\u5982\u4f55\u5728laravel\u4e2d\u4f7f\u7528\u63d2\u56fe\" alt=\"swoole\u534f\u7a0b\u5982\u4f55\u5728laravel\u4e2d\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>Swoole \u534f\u7a0b\u5728 Laravel \u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<p><strong>Swoole \u534f\u7a0b\u7b80\u4ecb<\/strong><\/p>\n<p>Swoole \u534f\u7a0b\u662f Swoole \u6846\u67b6\u63d0\u4f9b\u7684\u4e00\u79cd\u534f\u7a0b\u6a21\u578b\uff0c\u5b83\u5141\u8bb8 PHP \u7a0b\u5e8f\u5e76\u53d1\u5730\u6267\u884c\u591a\u4e2a\u4efb\u52a1\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u3002\u5b83\u57fa\u4e8e Linux \u5185\u6838\u4e2d\u7684 epoll \u4e8b\u4ef6\u673a\u5236\uff0c\u4f7f\u5f97 PHP \u4ee3\u7801\u53ef\u4ee5\u9ad8\u6548\u5730\u5904\u7406\u5927\u91cf\u3002<\/p>\n<p><strong>\u5728 Laravel \u4e2d\u4f7f\u7528 Swoole \u534f\u7a0b<\/strong><\/p>\n<p><strong>\u5b89\u88c5 Swoole \u6269\u5c55<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5 Swoole \u6269\u5c55\uff1a<\/p>\n<pre>composer require swoole\/swoole<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u521b\u5efa Swoole Http \u670d\u52a1\u5668<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a Swoole Http \u670d\u52a1\u5668\uff0c\u5b83\u5c06\u4f5c\u4e3a Laravel \u5e94\u7528\u7a0b\u5e8f\u7684\u5904\u7406\u7a0b\u5e8f\uff1a<\/p>\n<pre>use SwooleHttpServer;\n\n$server = new Server('0.0.0.0', 8080);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u518c Laravel \u8def\u7531<\/strong><\/p>\n<p>\u5c06 Laravel \u8def\u7531\u6ce8\u518c\u5230 Swoole Http \u670d\u52a1\u5668\u4e2d\uff1a<\/p>\n<pre>$server-&gt;on('request', function (SwooleHttpRequest $request, SwooleHttpResponse $response) {\n    $response-&gt;write(IlluminateHttpRequest::createFromBase($request)-&gt;route()-&gt;run());\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u542f\u52a8 Swoole \u670d\u52a1\u5668<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u542f\u52a8 Swoole \u670d\u52a1\u5668\uff1a<\/p>\n<pre>$server-&gt;start();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u6267\u884c\u8fd9\u4e9b\u6b65\u9aa4\uff0cLaravel \u5e94\u7528\u7a0b\u5e8f\u5c06\u4f7f\u7528 Swoole \u534f\u7a0b\u8fdb\u884c\u64cd\u4f5c\u3002\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u5e76\u53d1\u5904\u7406\u5927\u91cf\u8bf7\u6c42\uff0c\u540c\u65f6\u4fdd\u6301\u8f83\u4f4e\u7684\u8d44\u6e90\u6d88\u8017\u3002<\/p>\n<p><strong>\u4f18\u52bf<\/strong><\/p>\n<p>\u4f7f\u7528 Swoole \u534f\u7a0b\u5728 Laravel \u4e2d\u7684\u4f18\u52bf\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>\u5e76\u53d1\u5904\u7406\uff1a<\/strong>\u5141\u8bb8\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u3002<\/li>\n<li> <strong>\u9ad8\u6027\u80fd\uff1a<\/strong>\u57fa\u4e8e Linux epoll \u4e8b\u4ef6\u673a\u5236\uff0c\u53ef\u5feb\u901f\u9ad8\u6548\u5730\u5904\u7406\u8bf7\u6c42\u3002<\/li>\n<li> <strong>\u4f4e\u8d44\u6e90\u6d88\u8017\uff1a<\/strong>\u4e0e\u4f20\u7edf\u7684\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u65b9\u6cd5\u76f8\u6bd4\uff0c\u6240\u9700\u670d\u52a1\u5668\u8d44\u6e90\u66f4\u5c11\u3002<\/li>\n<li> <strong>\u6613\u4e8e\u96c6\u6210\uff1a<\/strong>Laravel \u6846\u67b6\u4e0e Swoole \u534f\u7a0b\u65e0\u7f1d\u96c6\u6210\uff0c\u4f7f\u7528\u7b80\u5355\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u534f\u7a0b\u5982\u4f55\u5728\u4e2d\u4f7f\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>laravel \u4e2d\u4f7f\u7528 swoole \u534f\u7a0b\u53ef\u4ee5\u5e76\u53d1\u5904\u7406\u5927\u91cf\u8bf7\u6c42\uff0c\u4f18\u52bf\u5305\u62ec\uff1a\u5e76\u53d1\u5904\u7406\uff1a\u5141\u8bb8\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u3002\u9ad8\u6027\u80fd\uff1a\u57fa\u4e8e linux epoll \u4e8b\u4ef6\u673a\u5236\uff0c\u9ad8\u6548\u5904\u7406\u8bf7\u6c42\u3002\u4f4e\u8d44\u6e90\u6d88\u8017\uff1a\u6240\u9700\u670d\u52a1\u5668\u8d44\u6e90\u66f4\u5c11\u3002\u6613\u4e8e\u96c6\u6210\uff1a\u4e0e laravel \u6846\u67b6\u65e0\u7f1d\u96c6\u6210\uff0c\u4f7f\u7528\u7b80\u5355\u3002 Swoole \u534f\u7a0b\u5728 Laravel \u4e2d\u7684\u5e94\u7528 Swoole \u534f\u7a0b\u7b80\u4ecb Swoole \u534f\u7a0b\u662f Swoole \u6846\u67b6\u63d0\u4f9b\u7684\u4e00\u79cd\u534f\u7a0b\u6a21\u578b\uff0c\u5b83\u5141\u8bb8 PHP \u7a0b\u5e8f\u5e76\u53d1\u5730\u6267\u884c\u591a\u4e2a\u4efb\u52a1\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u3002\u5b83\u57fa\u4e8e Linux \u5185\u6838\u4e2d\u7684 epoll \u4e8b\u4ef6\u673a\u5236\uff0c\u4f7f\u5f97 PHP \u4ee3\u7801\u53ef\u4ee5\u9ad8\u6548\u5730\u5904\u7406\u5927\u91cf\u3002 \u5728 Laravel \u4e2d\u4f7f\u7528 Swoole \u534f\u7a0b \u5b89\u88c5 Swoole \u6269\u5c55 \u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5 Swoole \u6269\u5c55\uff1a composer require swoole\/swoole \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa Swoole Http \u670d\u52a1\u5668 \u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a Swoole Http \u670d\u52a1\u5668\uff0c\u5b83\u5c06\u4f5c\u4e3a Laravel \u5e94\u7528\u7a0b\u5e8f\u7684\u5904\u7406\u7a0b\u5e8f\uff1a use SwooleHttpServer; $server [&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-25320","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25320","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=25320"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25320\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}