{"id":23835,"date":"2024-11-21T13:11:46","date_gmt":"2024-11-21T05:11:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23835\/"},"modified":"2024-11-21T13:11:46","modified_gmt":"2024-11-21T05:11:46","slug":"yii%e6%a1%86%e6%9e%b6%e4%b8%ad%e7%9a%84%e6%b6%88%e6%81%af%e9%98%9f%e5%88%97%ef%bc%9a%e5%ae%9e%e7%8e%b0%e5%bc%82%e6%ad%a5%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23835\/","title":{"rendered":"Yii\u6846\u67b6\u4e2d\u7684\u6d88\u606f\u961f\u5217\uff1a\u5b9e\u73b0\u5f02\u6b65\u5904\u7406"},"content":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u666e\u53ca\u548c\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0c\u6570\u636e\u91cf\u548c\u670d\u52a1\u7684\u590d\u6742\u7a0b\u5ea6\u4e0d\u65ad\u589e\u52a0\uff0c\u4e3a\u4e86\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\uff0c\u5f02\u6b65\u5904\u7406\u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u88ab\u5e7f\u6cdb\u5e94\u7528\u7684\u6280\u672f\u624b\u6bb5\u3002\u5728php\u5f00\u53d1\u4e2d\uff0c\u6d88\u606f\u961f\u5217\u662f\u5b9e\u73b0\u5f02\u6b65\u5904\u7406\u7684\u91cd\u8981\u5de5\u5177\u4e4b\u4e00\u3002\u5728yii\u6846\u67b6\u4e2d\uff0c\u4e5f\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u5584\u7684\u6d88\u606f\u961f\u5217\u7cfb\u7edf\uff0c\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5728yii\u6846\u67b6\u4e2d\u5982\u4f55\u4f7f\u7528\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u5f02\u6b65\u5904\u7406\u3002<\/p>\n<p>\u4e00\u3001\u6d88\u606f\u961f\u5217\u7684\u6982\u5ff5\u53ca\u5e94\u7528<\/p>\n<p>\u6d88\u606f\u961f\u5217\u662f\u4e00\u79cd\u5148\u8fdb\u5148\u51fa(FIFO)\u7684\u6d88\u606f\u5b58\u50a8\u65b9\u5f0f\uff0c\u6d88\u606f\u7684\u751f\u4ea7\u8005\u5c06\u6d88\u606f\u53d1\u9001\u5230\u961f\u5217\uff0c\u800c\u6d88\u606f\u7684\u6d88\u8d39\u8005\u5219\u53ef\u4ee5\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u6d88\u606f\u5e76\u8fdb\u884c\u5904\u7406\u3002\u5f53\u6d88\u606f\u7684\u5904\u7406\u9700\u8981\u5f88\u957f\u65f6\u95f4\u6216\u8005\u5904\u7406\u8fc7\u7a0b\u9700\u8981\u6d88\u8017\u5927\u91cf\u65f6\u95f4\u548c\u8d44\u6e90\u65f6\uff0c\u4f7f\u7528\u6d88\u606f\u961f\u5217\u53ef\u4ee5\u5c06\u6d88\u606f\u7684\u5904\u7406\u8fc7\u7a0b\u5f02\u6b65\u5316\uff0c\u907f\u514d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u8fd0\u884c\uff0c\u901a\u8fc7\u63d0\u524d\u5c06\u4efb\u52a1\u653e\u5165\u961f\u5217\uff0c\u5c06\u4efb\u52a1\u7684\u5904\u7406\u548c\u54cd\u5e94\u5206\u79bb\uff0c\u4ece\u800c\u63d0\u9ad8\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u5904\u7406\u80fd\u529b\u3002<\/p>\n<p>\u6d88\u606f\u961f\u5217\u7684\u5e94\u7528\u573a\u666f\u975e\u5e38\u5e7f\u6cdb\uff0c\u4f8b\u5982\uff1a<\/p>\n<ol>\n<li>\u56fe\u7247\u3001\u89c6\u9891\u7b49\u6587\u4ef6\u7684\u8f6c\u7801\u3001\u538b\u7f29\uff1b<\/li>\n<li>\u6570\u636e\u7684ETL\uff08Extract\u3001Transform\u3001Load\uff09\u8fc7\u7a0b\uff0c\u5373\u6570\u636e\u91c7\u96c6\u3001\u6e05\u6d17\u548c\u5bfc\u5165\uff1b<\/li>\n<li>\u6d88\u606f\u63a8\u9001\u670d\u52a1\uff1b<\/li>\n<li>\u90ae\u4ef6\u53d1\u9001\u3001\u77ed\u4fe1\u53d1\u9001\u7b49\u670d\u52a1\uff1b<\/li>\n<li>\u5f02\u6b65\u6570\u636e\u7edf\u8ba1\u3001\u62a5\u8868\u751f\u6210\u7b49\u4efb\u52a1\u3002<\/li>\n<\/ol>\n<p>\u4e8c\u3001Yii\u6846\u67b6\u4e2d\u7684\u6d88\u606f\u961f\u5217<\/p>\n<p>\u5728Yii\u6846\u67b6\u4e2d\uff0c\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u5584\u7684\u6d88\u606f\u961f\u5217\u7cfb\u7edf\uff0c\u5305\u62ec\u6d88\u606f\u53d1\u9001\u548c\u6d88\u8d39\u4e24\u4e2a\u90e8\u5206\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Yii\u6846\u67b6\u63d0\u4f9b\u7684\u961f\u5217\u7ec4\u4ef6\u6216\u8005\u7b2c\u4e09\u65b9\u6269\u5c55\uff08\u5982yii-queue\u3001Beanstalkd\u7b49\uff09\u6765\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u529f\u80fd\u3002<\/p>\n<ol>\n<li>Yii\u6846\u67b6\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6<\/li>\n<\/ol>\n<p>Yii\u6846\u67b6\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u6d88\u606f\u961f\u5217\u5904\u7406\u6d41\u7a0b\u3002\u5728Yii\u6846\u67b6\u4e2d\uff0c\u4f7f\u7528\u961f\u5217\u7ec4\u4ef6\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u521b\u5efa\u6d88\u606f\u5904\u7406\u7c7b<\/li>\n<\/ol>\n<p>\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6d88\u606f\u5904\u7406\u7c7b\uff0c\u5b9e\u73b0Queueable\u63a5\u53e3\u6765\u5b9a\u4e49\u6d88\u606f\u5904\u7406\u8fc7\u7a0b\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aExportTask\u7684\u6d88\u606f\u5904\u7406\u7c7b\uff0c\u5b9e\u73b0Queueable\u63a5\u53e3\uff0c\u5e76\u5728process\u65b9\u6cd5\u4e2d\u5b9e\u73b0\u5177\u4f53\u7684\u4efb\u52a1\u5904\u7406\u8fc7\u7a0b\uff1a<\/p>\n<pre>use yiiqueueQueueable;\n\nclass ExportTask implements Queueable\n{\n    public $data;\n\n    public function __construct($data)\n    {\n        $this-&amp;gt;data = $data;\n    }\n\n    public function handle($queue)\n    {\n        \/\/ \u5904\u7406\u5bfc\u51fa\u4efb\u52a1\n        \/\/ $this-&amp;gt;data\u5305\u542b\u5bfc\u51fa\u6240\u9700\u7684\u53c2\u6570\u548c\u6570\u636e\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u53d1\u9001\u6d88\u606f<\/li>\n<\/ol>\n<p>\u5728\u9700\u8981\u53d1\u9001\u6d88\u606f\u7684\u5730\u65b9\uff0c\u8c03\u7528Yii::$app-&gt;queue-&gt;push\u65b9\u6cd5\u5c06\u6d88\u606f\u53d1\u9001\u5230\u961f\u5217\u4e2d\uff1a<\/p>\n<pre>Yii::$app-&amp;gt;queue-&amp;gt;push(new ExportTask(['file' =&amp;gt; 'export.xlsx', 'data' =&amp;gt; $data]));<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u914d\u7f6e\u961f\u5217\u7ec4\u4ef6<\/li>\n<\/ol>\n<p>\u5728\u5e94\u7528\u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u4e00\u822c\u662fconfig\/console.php\uff09\u914d\u7f6e\u961f\u5217\u7ec4\u4ef6\uff1a<\/p>\n<pre>return [\n    \/\/ ...\n    'components' =&amp;gt; [\n        \/\/ ...\n        'queue' =&amp;gt; [\n            'class' =&amp;gt; yiiqueueedisQueue::class,\n            'redis' =&amp;gt; [\n                'class' =&amp;gt; yiiedisConnection::class,\n                'hostname' =&amp;gt; '127.0.0.1',\n                'port' =&amp;gt; 6379,\n                'database' =&amp;gt; 0,\n            ],\n            'channel' =&amp;gt; 'queue',\n        ],\n        \/\/ ...\n    ],\n    \/\/ ...\n];<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86redis\u4f5c\u4e3a\u6d88\u606f\u961f\u5217\u5b58\u50a8\uff0c\u540c\u65f6\u4f7f\u7528\u4e86redis\u4f5c\u4e3aYii\u6846\u67b6\u4e2d\u7684\u7f13\u5b58\u5b58\u50a8\uff0c\u4ece\u800c\u51cf\u5c11\u7cfb\u7edf\u7684\u8d44\u6e90\u5360\u7528\u3002<\/p>\n<ol>\n<li>\u542f\u52a8\u6d88\u8d39\u8fdb\u7a0b<\/li>\n<\/ol>\n<p>\u4f7f\u7528Yii\u6846\u67b6\u63d0\u4f9b\u7684console\u547d\u4ee4\u542f\u52a8\u6d88\u8d39\u8fdb\u7a0b\uff1a<\/p>\n<pre>yii queue\/listen<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u542f\u52a8\u540e\uff0c\u6d88\u8d39\u8fdb\u7a0b\u4f1a\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u76d1\u542c\u961f\u5217\u4e2d\u7684\u6d88\u606f\u5e76\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528Yii\u6846\u67b6\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cYii\u6846\u67b6\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6\u652f\u6301\u7684\u6d88\u606f\u5b58\u50a8\u65b9\u5f0f\u9664redis\u4ee5\u5916\u8fd8\u5305\u62ec\u6570\u636e\u5e93\u3001\u6587\u4ef6\u7b49\uff0c\u5177\u4f53\u5b9e\u73b0\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<ol>\n<li>\u7b2c\u4e09\u65b9\u6269\u5c55\u7684\u4f7f\u7528<\/li>\n<\/ol>\n<p>\u5982\u679c\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u7684\u6d88\u606f\u5b58\u50a8\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u6269\u5c55\uff08\u5982yii-queue\u3001Beanstalkd\u7b49\uff09\u6765\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u529f\u80fd\u3002\u4ee5yii-queue\u4e3a\u4f8b\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<ol>\n<li>\u5b89\u88c5\u6269\u5c55<\/li>\n<\/ol>\n<p>\u4f7f\u7528composer\u5b89\u88c5yii-queue\u6269\u5c55\uff1a<\/p>\n<pre>composer require yii2tech\/queue<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u914d\u7f6e\u5e94\u7528\u7ec4\u4ef6<\/li>\n<\/ol>\n<p>\u5728\u5e94\u7528\u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u4e00\u822c\u662fconfig\/console.php\uff09\u4e2d\u914d\u7f6e\u5e94\u7528\u7ec4\u4ef6\uff1a<\/p>\n<pre>return [\n    \/\/ ...\n    'components' =&amp;gt; [\n        \/\/ ...\n        'queue' =&amp;gt; [\n            'class' =&amp;gt; yiiqueuemqpQueue::class,\n            'host' =&amp;gt; '127.0.0.1',\n            'port' =&amp;gt; 5672,\n            'user' =&amp;gt; 'guest',\n            'password' =&amp;gt; 'guest',\n            'queueName' =&amp;gt; 'queue-name',\n        ],\n        \/\/ ...\n    ],\n    \/\/ ...\n];<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u914d\u7f6e\u4f7f\u7528\u4e86amqp\u4f5c\u4e3a\u6d88\u606f\u5b58\u50a8\uff0c\u9700\u8981\u5b89\u88c5php-amqp\u6269\u5c55\u3002<\/p>\n<ol>\n<li>\u7f16\u5199\u6d88\u606f\u5904\u7406\u7c7b<\/li>\n<\/ol>\n<p>\u5728Yii\u6846\u67b6\u4e2d\u4f7f\u7528yii-queue\uff0c\u6211\u4eec\u9700\u8981\u5b9e\u73b0Job\u63a5\u53e3\u6765\u5b9a\u4e49\u4efb\u52a1\u5904\u7406\u8fc7\u7a0b\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aExportTask\u7684\u6d88\u606f\u5904\u7406\u7c7b\uff1a<\/p>\n<pre>use yiiqueueJob;\n\nclass ExportTask implements Job\n{\n    public $data;\n\n    public function __construct($data)\n    {\n        $this-&amp;gt;data = $data;\n    }\n\n    public function execute($queue)\n    {\n        \/\/ \u5904\u7406\u5bfc\u51fa\u4efb\u52a1\n        \/\/ $this-&amp;gt;data\u5305\u542b\u5bfc\u51fa\u6240\u9700\u7684\u53c2\u6570\u548c\u6570\u636e\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u53d1\u9001\u6d88\u606f<\/li>\n<\/ol>\n<p>\u5728\u9700\u8981\u53d1\u9001\u6d88\u606f\u7684\u5730\u65b9\uff0c\u8c03\u7528Yii::$app-&gt;queue-&gt;push\u65b9\u6cd5\u5c06\u6d88\u606f\u53d1\u9001\u5230\u961f\u5217\u4e2d\uff1a<\/p>\n<pre>Yii::$app-&amp;gt;queue-&amp;gt;push(new ExportTask(['file' =&amp;gt; 'export.xlsx', 'data' =&amp;gt; $data]));<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u542f\u52a8\u6d88\u8d39\u8fdb\u7a0b<\/li>\n<\/ol>\n<p>\u4f7f\u7528Yii\u6846\u67b6\u63d0\u4f9b\u7684console\u547d\u4ee4\u542f\u52a8\u6d88\u8d39\u8fdb\u7a0b\uff1a<\/p>\n<pre>yii queue\/run<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u542f\u52a8\u540e\uff0c\u6d88\u8d39\u8fdb\u7a0b\u4f1a\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u76d1\u542c\u961f\u5217\u4e2d\u7684\u6d88\u606f\u5e76\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528yii-queue\u6269\u5c55\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cyii-queue\u6269\u5c55\u652f\u6301\u7684\u6d88\u606f\u5b58\u50a8\u65b9\u5f0f\u9664amqp\u4ee5\u5916\u8fd8\u5305\u62ec\u6570\u636e\u5e93\u3001redis\u3001beanstalkd\u7b49\u3002<\/p>\n<p>\u4e09\u3001\u6d88\u606f\u961f\u5217\u7684\u4f18\u5316<\/p>\n<p>\u5728\u4f7f\u7528\u6d88\u606f\u961f\u5217\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6d88\u606f\u961f\u5217\u7684\u6027\u80fd\u3001\u5b89\u5168\u6027\u7b49\u65b9\u9762\u8fdb\u884c\u4f18\u5316\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u4f18\u5316\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>\u961f\u5217\u8fde\u63a5\u590d\u7528<\/li>\n<\/ol>\n<p>\u6bcf\u6b21\u4f7f\u7528\u961f\u5217\u7ec4\u4ef6\u5904\u7406\u4efb\u52a1\u65f6\uff0c\u90fd\u9700\u8981\u91cd\u65b0\u8fde\u63a5\u961f\u5217\u670d\u52a1\u5668\uff0c\u9891\u7e41\u521b\u5efa\u8fde\u63a5\u4f1a\u4e25\u91cd\u5f71\u54cd\u6027\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u8fde\u63a5\u6c60\u6216\u8005\u5355\u4f8b\u6a21\u5f0f\u6765\u590d\u7528\u8fde\u63a5\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<ol>\n<li>\u6d88\u606f\u6295\u9012\u786e\u8ba4<\/li>\n<\/ol>\n<p>\u5728\u53d1\u9001\u6d88\u606f\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u6d88\u606f\u6295\u9012\u786e\u8ba4\u673a\u5236\u6765\u786e\u4fdd\u6d88\u606f\u88ab\u6210\u529f\u6295\u9012\u5230\u961f\u5217\u670d\u52a1\u5668\u3002\u961f\u5217\u670d\u52a1\u5668\u8fd4\u56de\u6295\u9012\u6210\u529f\u7684\u786e\u8ba4\u6d88\u606f\u540e\uff0c\u6211\u4eec\u624d\u80fd\u5c06\u6d88\u606f\u4ece\u4efb\u52a1\u5217\u8868\u4e2d\u5220\u9664\uff0c\u4ece\u800c\u4fdd\u8bc1\u6d88\u606f\u7684\u4e0d\u91cd\u590d\u5904\u7406\u3002<\/p>\n<ol>\n<li>\u6d88\u606f\u91cd\u8bd5\u673a\u5236<\/li>\n<\/ol>\n<p>\u5f53\u4efb\u52a1\u5904\u7406\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u5f02\u5e38\u6216\u8005\u5176\u4ed6\u9519\u8bef\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6d88\u606f\u91cd\u8bd5\u673a\u5236\u6765\u91cd\u65b0\u6295\u9012\u6d88\u606f\u3002\u4f8b\u5982\uff0c\u5728\u5904\u7406\u5bfc\u51fa\u4efb\u52a1\u65f6\uff0c\u5982\u679c\u751f\u6210\u6587\u4ef6\u5931\u8d25\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4efb\u52a1\u91cd\u65b0\u6295\u9012\u5230\u961f\u5217\u4e2d\uff0c\u7b49\u5f85\u4e0b\u6b21\u5904\u7406\u3002<\/p>\n<ol>\n<li>\u5b89\u5168\u6027\u8003\u8651<\/li>\n<\/ol>\n<p>\u6d88\u606f\u961f\u5217\u7684\u5b89\u5168\u6027\u975e\u5e38\u5173\u952e\uff0c\u5728\u5904\u7406\u654f\u611f\u6570\u636e\u65f6\u5c24\u5176\u91cd\u8981\u3002\u4e3a\u4e86\u4fdd\u8bc1\u6d88\u606f\u7684\u5b89\u5168\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u6d88\u606f\u8fdb\u884c\u52a0\u5bc6\u3001\u89e3\u5bc6\u5904\u7406\uff1b\u540c\u65f6\u9700\u8981\u6ce8\u610f\u8bbe\u7f6e\u961f\u5217\u8fde\u63a5\u7684\u5b89\u5168\u914d\u7f6e\uff0c\u907f\u514d\u88ab\u6076\u610f\u653b\u51fb\u3002<\/p>\n<p>\u56db\u3001\u603b\u7ed3<\/p>\n<p>\u6d88\u606f\u961f\u5217\u662f\u5b9e\u73b0\u5f02\u6b65\u5904\u7406\u7684\u6709\u6548\u5de5\u5177\uff0c\u5df2\u7ecf\u5728\u5f88\u591a\u5927\u578b\u7cfb\u7edf\u4e2d\u5f97\u5230\u5e7f\u6cdb\u5e94\u7528\u3002\u5728Yii\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6\u6216\u8005\u7b2c\u4e09\u65b9\u6269\u5c55\uff08\u5982yii-queue\u3001Beanstalkd\u7b49\uff09\u6765\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u529f\u80fd\uff0c\u901a\u8fc7\u63d0\u9ad8\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u5904\u7406\u80fd\u529b\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u548c\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u3002\u5728\u4f7f\u7528\u6d88\u606f\u961f\u5217\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u961f\u5217\u8fde\u63a5\u3001\u6d88\u606f\u6295\u9012\u786e\u8ba4\u3001\u6d88\u606f\u91cd\u8bd5\u548c\u5b89\u5168\u6027\u7b49\u65b9\u9762\u8fdb\u884c\u4f18\u5316\uff0c\u4ece\u800c\u786e\u4fdd\u6d88\u606f\u7684\u53ef\u9760\u6027\u548c\u4fdd\u5bc6\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fYii\u6846\u67b6\u4e2d\u7684\u6d88\u606f\u961f\u5217\uff1a\u5b9e\u73b0\u5f02\u6b65\u5904\u7406\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>\u968f\u7740\u4e92\u8054\u7f51\u7684\u666e\u53ca\u548c\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0c\u6570\u636e\u91cf\u548c\u670d\u52a1\u7684\u590d\u6742\u7a0b\u5ea6\u4e0d\u65ad\u589e\u52a0\uff0c\u4e3a\u4e86\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\uff0c\u5f02\u6b65\u5904\u7406\u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u88ab\u5e7f\u6cdb\u5e94\u7528\u7684\u6280\u672f\u624b\u6bb5\u3002\u5728php\u5f00\u53d1\u4e2d\uff0c\u6d88\u606f\u961f\u5217\u662f\u5b9e\u73b0\u5f02\u6b65\u5904\u7406\u7684\u91cd\u8981\u5de5\u5177\u4e4b\u4e00\u3002\u5728yii\u6846\u67b6\u4e2d\uff0c\u4e5f\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u5584\u7684\u6d88\u606f\u961f\u5217\u7cfb\u7edf\uff0c\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5728yii\u6846\u67b6\u4e2d\u5982\u4f55\u4f7f\u7528\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u5f02\u6b65\u5904\u7406\u3002 \u4e00\u3001\u6d88\u606f\u961f\u5217\u7684\u6982\u5ff5\u53ca\u5e94\u7528 \u6d88\u606f\u961f\u5217\u662f\u4e00\u79cd\u5148\u8fdb\u5148\u51fa(FIFO)\u7684\u6d88\u606f\u5b58\u50a8\u65b9\u5f0f\uff0c\u6d88\u606f\u7684\u751f\u4ea7\u8005\u5c06\u6d88\u606f\u53d1\u9001\u5230\u961f\u5217\uff0c\u800c\u6d88\u606f\u7684\u6d88\u8d39\u8005\u5219\u53ef\u4ee5\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u6d88\u606f\u5e76\u8fdb\u884c\u5904\u7406\u3002\u5f53\u6d88\u606f\u7684\u5904\u7406\u9700\u8981\u5f88\u957f\u65f6\u95f4\u6216\u8005\u5904\u7406\u8fc7\u7a0b\u9700\u8981\u6d88\u8017\u5927\u91cf\u65f6\u95f4\u548c\u8d44\u6e90\u65f6\uff0c\u4f7f\u7528\u6d88\u606f\u961f\u5217\u53ef\u4ee5\u5c06\u6d88\u606f\u7684\u5904\u7406\u8fc7\u7a0b\u5f02\u6b65\u5316\uff0c\u907f\u514d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u8fd0\u884c\uff0c\u901a\u8fc7\u63d0\u524d\u5c06\u4efb\u52a1\u653e\u5165\u961f\u5217\uff0c\u5c06\u4efb\u52a1\u7684\u5904\u7406\u548c\u54cd\u5e94\u5206\u79bb\uff0c\u4ece\u800c\u63d0\u9ad8\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u5904\u7406\u80fd\u529b\u3002 \u6d88\u606f\u961f\u5217\u7684\u5e94\u7528\u573a\u666f\u975e\u5e38\u5e7f\u6cdb\uff0c\u4f8b\u5982\uff1a \u56fe\u7247\u3001\u89c6\u9891\u7b49\u6587\u4ef6\u7684\u8f6c\u7801\u3001\u538b\u7f29\uff1b \u6570\u636e\u7684ETL\uff08Extract\u3001Transform\u3001Load\uff09\u8fc7\u7a0b\uff0c\u5373\u6570\u636e\u91c7\u96c6\u3001\u6e05\u6d17\u548c\u5bfc\u5165\uff1b \u6d88\u606f\u63a8\u9001\u670d\u52a1\uff1b \u90ae\u4ef6\u53d1\u9001\u3001\u77ed\u4fe1\u53d1\u9001\u7b49\u670d\u52a1\uff1b \u5f02\u6b65\u6570\u636e\u7edf\u8ba1\u3001\u62a5\u8868\u751f\u6210\u7b49\u4efb\u52a1\u3002 \u4e8c\u3001Yii\u6846\u67b6\u4e2d\u7684\u6d88\u606f\u961f\u5217 \u5728Yii\u6846\u67b6\u4e2d\uff0c\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u5584\u7684\u6d88\u606f\u961f\u5217\u7cfb\u7edf\uff0c\u5305\u62ec\u6d88\u606f\u53d1\u9001\u548c\u6d88\u8d39\u4e24\u4e2a\u90e8\u5206\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Yii\u6846\u67b6\u63d0\u4f9b\u7684\u961f\u5217\u7ec4\u4ef6\u6216\u8005\u7b2c\u4e09\u65b9\u6269\u5c55\uff08\u5982yii-queue\u3001Beanstalkd\u7b49\uff09\u6765\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u529f\u80fd\u3002 Yii\u6846\u67b6\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6 Yii\u6846\u67b6\u5185\u7f6e\u7684\u961f\u5217\u7ec4\u4ef6\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u6d88\u606f\u961f\u5217\u5904\u7406\u6d41\u7a0b\u3002\u5728Yii\u6846\u67b6\u4e2d\uff0c\u4f7f\u7528\u961f\u5217\u7ec4\u4ef6\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u6d88\u606f\u5904\u7406\u7c7b \u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6d88\u606f\u5904\u7406\u7c7b\uff0c\u5b9e\u73b0Queueable\u63a5\u53e3\u6765\u5b9a\u4e49\u6d88\u606f\u5904\u7406\u8fc7\u7a0b\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aExportTask\u7684\u6d88\u606f\u5904\u7406\u7c7b\uff0c\u5b9e\u73b0Queueable\u63a5\u53e3\uff0c\u5e76\u5728process\u65b9\u6cd5\u4e2d\u5b9e\u73b0\u5177\u4f53\u7684\u4efb\u52a1\u5904\u7406\u8fc7\u7a0b\uff1a use yiiqueueQueueable; class ExportTask implements Queueable { public $data; public function __construct($data) { $this-&amp;gt;data = $data; } public function handle($queue) { \/\/ \u5904\u7406\u5bfc\u51fa\u4efb\u52a1 \/\/ $this-&amp;gt;data\u5305\u542b\u5bfc\u51fa\u6240\u9700\u7684\u53c2\u6570\u548c\u6570\u636e } } \u767b\u5f55\u540e\u590d\u5236 \u53d1\u9001\u6d88\u606f \u5728\u9700\u8981\u53d1\u9001\u6d88\u606f\u7684\u5730\u65b9\uff0c\u8c03\u7528Yii::$app-&gt;queue-&gt;push\u65b9\u6cd5\u5c06\u6d88\u606f\u53d1\u9001\u5230\u961f\u5217\u4e2d\uff1a Yii::$app-&amp;gt;queue-&amp;gt;push(new ExportTask([&#8216;file&#8217; =&amp;gt; &#8216;export.xlsx&#8217;, &#8216;data&#8217; =&amp;gt; $data])); \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u914d\u7f6e\u961f\u5217\u7ec4\u4ef6 [&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-23835","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23835","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=23835"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23835\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}