{"id":48250,"date":"2024-12-02T10:35:55","date_gmt":"2024-12-02T02:35:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48250\/"},"modified":"2024-12-02T10:35:55","modified_gmt":"2024-12-02T02:35:55","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48250\/","title":{"rendered":"PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f<\/h1>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<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 decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730004996671dc8043191d.jpg\" class=\"aligncenter\" 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>\u4e3a\u4e86\u6f14\u793a\u5f02\u6b65\u6267\u884c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>pcntl_signal<\/code> \u51fd\u6570\u6ce8\u518c\u4e00\u4e2a\u54cd\u5e94 <code>SIGUSR1<\/code> \u4fe1\u53f7\u7684\u56de\u8c03\u51fd\u6570\uff1a<\/p>\n<pre>&lt;?php\n\ndeclare(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>\u5f53 <code>SIGUSR1<\/code> \u4fe1\u53f7\u88ab\u89e6\u53d1\u65f6\uff0c<code>signalHandler<\/code> \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\n\ndeclare(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>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c<code>handleQueue<\/code> \u51fd\u6570\u5728\u6536\u5230 <code>SIGUSR1<\/code> \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>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aPHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300aPHP \u51fd\u6570\u4e8b\u4ef6\u5904\u7406\u6280\u672f\u662f\u5426\u652f\u6301\u5f02\u6b65\u5904\u7406\uff1f\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 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 \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 \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 [&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-48250","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48250","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=48250"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48250\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}