{"id":765,"date":"2024-11-07T16:45:58","date_gmt":"2024-11-07T08:45:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/765\/"},"modified":"2024-11-07T16:45:58","modified_gmt":"2024-11-07T08:45:58","slug":"php-%e5%87%bd%e6%95%b0%e4%ba%8b%e4%bb%b6%e5%a4%84%e7%90%86%e6%8a%80%e6%9c%af%e6%98%af%e5%90%a6%e6%94%af%e6%8c%81%e5%bc%82%e6%ad%a5%e5%a4%84%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/765\/","title":{"rendered":"PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f"},"content":{"rendered":"<p>php \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u652f\u6301\u5f02\u6b65\u6267\u884c\uff0c\u5141\u8bb8\u51fd\u6570\u5728\u89e6\u53d1\u4e8b\u4ef6\u65f6\u7acb\u5373\u8fd4\u56de\uff0c\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u4ee3\u7801\u3002\u56de\u8c03\u51fd\u6570\u5728\u4e8b\u4ef6\u89e6\u53d1\u65f6\u88ab\u5f02\u6b65\u8c03\u7528\uff0c\u7528\u4e8e\u54cd\u5e94\u7279\u5b9a\u4e8b\u4ef6\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1158\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172839384369214.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172839384369214.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172839384369214-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172839384369214-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u7684\u5f02\u6b65\u6267\u884c<\/strong><\/p>\n<p>PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u5141\u8bb8\u901a\u8fc7\u6ce8\u518c\u56de\u8c03\u51fd\u6570\u6765\u54cd\u5e94\u5f02\u6b65\u4e8b\u4ef6\u3002\u4e0e\u4f20\u7edf\u540c\u6b65\u6267\u884c\u4e0d\u540c\uff0c\u5f02\u6b65\u6267\u884c\u5141\u8bb8\u51fd\u6570\u5728\u89e6\u53d1\u4e8b\u4ef6\u65f6\u7acb\u5373\u8fd4\u56de\uff0c\u800c\u4e0d\u5fc5\u7b49\u5f85\u4e8b\u4ef6\u5b8c\u6210\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<p>\u4e3a\u4e86\u6f14\u793a\u5f02\u6b65\u6267\u884c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 pcntl_signal \u51fd\u6570\u6ce8\u518c\u4e00\u4e2a\u54cd\u5e94 SIGUSR1 \u4fe1\u53f7\u7684\u56de\u8c03\u51fd\u6570\uff1a<\/p>\n<pre>&lt;?php declare(strict_types=1);\n\nuse function pcntl_signal;\n\nfunction signalHandler()\n{\n    \/\/ \u5904\u7406\u4fe1\u53f7\n}\n\npcntl_signal(SIGUSR1, 'signalHandler');\n\n\/\/ \u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5f53 SIGUSR1 \u4fe1\u53f7\u88ab\u89e6\u53d1\u65f6\uff0csignalHandler \u51fd\u6570\u5c06\u88ab\u5f02\u6b65\u8c03\u7528\uff0c\u800c\u4e3b\u7a0b\u5e8f\u5c06\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u4efb\u52a1\u961f\u5217\u5904\u7406<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u8fdb\u884c\u4efb\u52a1\u961f\u5217\u5904\u7406\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;?php declare(strict_types=1);\n\nuse function pcntl_signal;\n\nfunction handleQueue()\n{\n    \/\/ \u63a5\u6536\u4efb\u52a1\n    \/\/ \u5904\u7406\u4efb\u52a1\n}\n\npcntl_signal(SIGUSR1, 'handleQueue');\n\n\/\/ \u7b49\u5f85\u4efb\u52a1\nwhile (true) {\n    pcntl_signal_dispatch();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0chandleQueue \u51fd\u6570\u5728\u6536\u5230 SIGUSR1 \u4fe1\u53f7\u65f6\u88ab\u5f02\u6b65\u8c03\u7528\uff0c\u8d1f\u8d23\u63a5\u6536\u548c\u5904\u7406\u4efb\u52a1\u3002\u4e3b\u7a0b\u5e8f\u5219\u8fdb\u5165\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff0c\u7b49\u5f85\u4efb\u52a1\u7684\u5230\u6765\u3002<\/p>\n<p><strong>\u6ce8\u610f<\/strong><\/p>\n<p>PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u652f\u6301\u5f02\u6b65\u6267\u884c\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5b9e\u9645\u4f7f\u7528\u65f6\u53ef\u80fd\u53d7\u5230\u64cd\u4f5c\u7cfb\u7edf\u9650\u5236\u6216\u5176\u4ed6\u56e0\u7d20\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fPHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f\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>php \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u652f\u6301\u5f02\u6b65\u6267\u884c\uff0c\u5141\u8bb8\u51fd\u6570\u5728\u89e6\u53d1\u4e8b\u4ef6\u65f6\u7acb\u5373\u8fd4\u56de\uff0c\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u4ee3\u7801\u3002\u56de\u8c03\u51fd\u6570\u5728\u4e8b\u4ef6\u89e6\u53d1\u65f6\u88ab\u5f02\u6b65\u8c03\u7528\uff0c\u7528\u4e8e\u54cd\u5e94\u7279\u5b9a\u4e8b\u4ef6\u3002 PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u7684\u5f02\u6b65\u6267\u884c PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u5141\u8bb8\u901a\u8fc7\u6ce8\u518c\u56de\u8c03\u51fd\u6570\u6765\u54cd\u5e94\u5f02\u6b65\u4e8b\u4ef6\u3002\u4e0e\u4f20\u7edf\u540c\u6b65\u6267\u884c\u4e0d\u540c\uff0c\u5f02\u6b65\u6267\u884c\u5141\u8bb8\u51fd\u6570\u5728\u89e6\u53d1\u4e8b\u4ef6\u65f6\u7acb\u5373\u8fd4\u56de\uff0c\u800c\u4e0d\u5fc5\u7b49\u5f85\u4e8b\u4ef6\u5b8c\u6210\u3002 \u4ee3\u7801\u793a\u4f8b \u7acb\u5373\u5b66\u4e60\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b \u4e3a\u4e86\u6f14\u793a\u5f02\u6b65\u6267\u884c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 pcntl_signal \u51fd\u6570\u6ce8\u518c\u4e00\u4e2a\u54cd\u5e94 SIGUSR1 \u4fe1\u53f7\u7684\u56de\u8c03\u51fd\u6570\uff1a &lt;?php declare(strict_types=1); use function pcntl_signal; function signalHandler() { \/\/ \u5904\u7406\u4fe1\u53f7 } pcntl_signal(SIGUSR1, &#8216;signalHandler&#8217;); \/\/ \u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4ee3\u7801 \u767b\u5f55\u540e\u590d\u5236 \u5f53 SIGUSR1 \u4fe1\u53f7\u88ab\u89e6\u53d1\u65f6\uff0csignalHandler \u51fd\u6570\u5c06\u88ab\u5f02\u6b65\u8c03\u7528\uff0c\u800c\u4e3b\u7a0b\u5e8f\u5c06\u7ee7\u7eed\u6267\u884c\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a\u4efb\u52a1\u961f\u5217\u5904\u7406 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u8fdb\u884c\u4efb\u52a1\u961f\u5217\u5904\u7406\u7684\u793a\u4f8b\uff1a &lt;?php declare(strict_types=1); use function pcntl_signal; function handleQueue() { \/\/ \u63a5\u6536\u4efb\u52a1 \/\/ \u5904\u7406\u4efb\u52a1 } pcntl_signal(SIGUSR1, &#8216;handleQueue&#8217;); \/\/ \u7b49\u5f85\u4efb\u52a1 while (true) { [&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-765","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/765","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=765"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/765\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}