{"id":25312,"date":"2024-11-21T12:25:18","date_gmt":"2024-11-21T04:25:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25312\/"},"modified":"2024-11-21T12:25:18","modified_gmt":"2024-11-21T04:25:18","slug":"swoole_process-%e6%80%8e%e4%b9%88%e8%ae%a9%e7%94%a8%e6%88%b7%e5%88%87%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25312\/","title":{"rendered":"swoole_process \u600e\u4e48\u8ba9\u7528\u6237\u5207\u6362"},"content":{"rendered":"<blockquote><p>\n  swoole process \u4e2d\u53ef\u4ee5\u8ba9\u7528\u6237\u5207\u6362\uff0c\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u4e3a\uff1a\u521b\u5efa\u8fdb\u7a0b\uff1b\u8bbe\u7f6e\u8fdb\u7a0b\u7528\u6237\uff1b\u542f\u52a8\u8fdb\u7a0b\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040918212479474.jpg\" class=\"aligncenter\" title=\"swoole_process \u600e\u4e48\u8ba9\u7528\u6237\u5207\u6362\u63d2\u56fe\" alt=\"swoole_process \u600e\u4e48\u8ba9\u7528\u6237\u5207\u6362\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Swoole Process \u4e2d\u8ba9\u7528\u6237\u5207\u6362<\/strong><\/p>\n<p>Swoole Process \u662f\u4e00\u4e2a PHP \u6269\u5c55\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u521b\u5efa\u548c\u7ba1\u7406\u591a\u8fdb\u7a0b\u5e76\u53d1\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u8fdb\u7a0b\u4e4b\u95f4\u5207\u6362\u7528\u6237\u3002<\/p>\n<p><strong>\u65b9\u6cd5<\/strong><\/p>\n<p>\u8981\u8ba9\u7528\u6237\u5728 Swoole Process \u4e2d\u5207\u6362\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u8fdb\u7a0b<\/strong><\/li>\n<\/ol>\n<pre>$process = new SwooleProcess('process_function', false, false);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u8bbe\u7f6e\u8fdb\u7a0b\u7528\u6237<\/strong><\/li>\n<\/ol>\n<pre>$process-&gt;setUser('username');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d username \u662f\u8981\u5207\u6362\u5230\u7684\u7528\u6237\u3002<\/p>\n<ol>\n<li><strong>\u542f\u52a8\u8fdb\u7a0b<\/strong><\/li>\n<\/ol>\n<pre>$process-&gt;start();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u521b\u5efa\u5e76\u542f\u52a8\u4e00\u4e2a\u5207\u6362\u5230\u7528\u6237 www-data \u7684\u8fdb\u7a0b\uff1a<\/p>\n<pre>$process = new SwooleProcess('process_function', false, false);\n$process-&gt;setUser('www-data');\n$process-&gt;start();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f<\/strong><\/p>\n<ul>\n<li>\u53ea\u6709\u5728\u5177\u6709\u76f8\u5e94\u6743\u9650\u7684\u60c5\u51b5\u4e0b\uff0c\u624d\u80fd\u5c06\u8fdb\u7a0b\u5207\u6362\u5230\u53e6\u4e00\u4e2a\u7528\u6237\u3002<\/li>\n<li>\u786e\u4fdd\u60a8\u6b63\u5728\u5207\u6362\u5230\u7684\u7528\u6237\u5177\u6709\u6267\u884c\u8fdb\u7a0b\u51fd\u6570\u6240\u9700\u7684\u6743\u9650\u3002<\/li>\n<li>\u5207\u6362\u7528\u6237\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8fdb\u7a0b\u8bbf\u95ee\u4e0d\u540c\u7684\u6587\u4ef6\u548c\u5176\u4ed6\u8d44\u6e90\uff0c\u56e0\u6b64\u8981\u5c0f\u5fc3\u4f7f\u7528\u6b64\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f_process \u600e\u4e48\u8ba9\u7528\u6237\u5207\u6362\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 process \u4e2d\u53ef\u4ee5\u8ba9\u7528\u6237\u5207\u6362\uff0c\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u4e3a\uff1a\u521b\u5efa\u8fdb\u7a0b\uff1b\u8bbe\u7f6e\u8fdb\u7a0b\u7528\u6237\uff1b\u542f\u52a8\u8fdb\u7a0b\u3002 \u5982\u4f55\u5728 Swoole Process \u4e2d\u8ba9\u7528\u6237\u5207\u6362 Swoole Process \u662f\u4e00\u4e2a PHP \u6269\u5c55\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u521b\u5efa\u548c\u7ba1\u7406\u591a\u8fdb\u7a0b\u5e76\u53d1\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u8fdb\u7a0b\u4e4b\u95f4\u5207\u6362\u7528\u6237\u3002 \u65b9\u6cd5 \u8981\u8ba9\u7528\u6237\u5728 Swoole Process \u4e2d\u5207\u6362\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u8fdb\u7a0b $process = new SwooleProcess(&#8216;process_function&#8217;, false, false); \u767b\u5f55\u540e\u590d\u5236 \u8bbe\u7f6e\u8fdb\u7a0b\u7528\u6237 $process-&gt;setUser(&#8216;username&#8217;); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d username \u662f\u8981\u5207\u6362\u5230\u7684\u7528\u6237\u3002 \u542f\u52a8\u8fdb\u7a0b $process-&gt;start(); \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b \u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u521b\u5efa\u5e76\u542f\u52a8\u4e00\u4e2a\u5207\u6362\u5230\u7528\u6237 www-data \u7684\u8fdb\u7a0b\uff1a $process = new SwooleProcess(&#8216;process_function&#8217;, false, false); $process-&gt;setUser(&#8216;www-data&#8217;); $process-&gt;start(); \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f \u53ea\u6709\u5728\u5177\u6709\u76f8\u5e94\u6743\u9650\u7684\u60c5\u51b5\u4e0b\uff0c\u624d\u80fd\u5c06\u8fdb\u7a0b\u5207\u6362\u5230\u53e6\u4e00\u4e2a\u7528\u6237\u3002 \u786e\u4fdd\u60a8\u6b63\u5728\u5207\u6362\u5230\u7684\u7528\u6237\u5177\u6709\u6267\u884c\u8fdb\u7a0b\u51fd\u6570\u6240\u9700\u7684\u6743\u9650\u3002 \u5207\u6362\u7528\u6237\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8fdb\u7a0b\u8bbf\u95ee\u4e0d\u540c\u7684\u6587\u4ef6\u548c\u5176\u4ed6\u8d44\u6e90\uff0c\u56e0\u6b64\u8981\u5c0f\u5fc3\u4f7f\u7528\u6b64\u529f\u80fd\u3002 \u4ee5\u4e0a\u5c31\u662f_process \u600e\u4e48\u8ba9\u7528\u6237\u5207\u6362\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-25312","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25312","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=25312"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25312\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}