×ðÁú¿­Ê±

ÔõÑùʹÓÃThinkPHP6¾ÙÐÐÓʼþÐÐÁд¦Öóͷ£ £¿

Ëæ×ÅwebÓ¦ÓóÌÐòµÄÔö¶à £¬¹ØÓÚ·¢ËÍÓʼþµÄÐèÇóÒ²Ô½À´Ô½´ó¡£ÔÚijЩÇéÐÎÏ £¬ÐèÒªÅúÁ¿·¢ËÍÓʼþ»ò½«Óʼþ·¢Ë͵½ÐÐÁÐÖд¦Öóͷ£ÒÔÌá¸ßÐÔÄÜ¡£thinkphp 6ÖÐÌṩÁËÀû±ãµÄÓʼþ·¢ËͺÍÐÐÁд¦Öóͷ£¹¦Ð§ £¬±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphp 6¾ÙÐÐÓʼþÐÐÁд¦Öóͷ£¡£

Ò»¡¢×°Öò¢ÉèÖÃÐÐÁÐЧÀÍ

1.×°ÖÃRedis

RedisÊÇÒ»¸ö¿ªÔ´µÄÄÚ´æÊý¾Ý½á¹¹´æ´¢Ð§ÀÍÆ÷ £¬ÓÃ×÷Êý¾Ý¿â¡¢»º´æºÍÐÂÎÅÊðÀí¡£ÓÉÓÚÐÐÁеÄÊý¾Ý±ØÐèÒª³¤ÆÚ»¯ £¬ÒÔÊÇÐèҪͨ¹ýRedisÀ´ÉúÑÄÐÐÁÐÊý¾Ý¡£×°ÖÃRedis¿ÉÒԲο¼¹Ù·½Îĵµ¼°ÆäËûÔÚÏ߽̳Ì¡£

2.ÉèÖÃÐÐÁÐÅþÁ¬

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

ÔÚThinkPHPµÄÉèÖÃÎļþconfig/queue.phpÖÐÉèÖÃÐÐÁÐÅþÁ¬ £¬Ê¾ÀýÈçÏ£º

return [
    // ĬÈÏÇý¶¯
    'default' => env('queue.driver', 'redis'),

    // ÐÐÁÐÅþÁ¬²ÎÊý
    'connections' => [
        'sync' => [
            'driver' => 'sync',
        ],
        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => env('queue.redis.queue', 'default'),
            'retry_after' => 90,
            'block_for' => null,
        ],
    ],

    // ¼àÌýµÄʹÃüÀàÃüÃû¿Õ¼ä
    'queue_class' => [
        // 'AppJobs'
    ],
];

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬defaultÊÇĬÈϵÄÐÐÁÐÇý¶¯ £¬ÕâÀïÉèÖÃΪredis¡£connectionsÖÐÉèÖÃÁËredisÇý¶¯µÄÏà¹Ø²ÎÊý £¬°üÀ¨ÅþÁ¬Ãû¡¢ÅþÁ¬Çý¶¯¡¢ÅþÁ¬µÄqueueÐÐÁÐÃûµÈ¡£queue_classÓÃÀ´¼àÌýÖ´ÐÐʹÃüµÄÀàµÄÃüÃû¿Õ¼ä¡£

3.Æô¶¯ÐÐÁмàÌý

ÔÚÏÂÁîÐÐÖÐÆô¶¯ÐÐÁмàÌýÆ÷ £¬¿ÉÒÔ½«ÐÐÁÐÖеÄʹÃüÖðһȡ³ö²¢Ö´ÐС£Ê¾ÀýÈçÏ£º

php think queue:listen

µÇ¼ºó¸´ÖÆ

¶þ¡¢Ê¹ÓÃÐÐÁз¢ËÍÓʼþ

1.½¨ÉèÓʼþ·¢ËÍʹÃü

ÔÚapp/jobĿ¼Öн¨ÉèÒ»¸öÓʼþ·¢ËÍʹÃüÀà £¬²¢±àдÏà¹ØÂß¼­¡£ÀýÈç·¢ËÍÓʼþµÄʹÃüÀàSnedMailJob£º

<?php
namespace appjob;

use appcommonMail;
use thinkqueueJob;

class SendMailJob
{
    /**
     * Send the email message.
     *
     * @param  Job  $job
     * @param  array  $data email message data
     */
    public function fire(Job $job, $data)
    {
        try {
            // ·¢ËÍÓʼþ
            Mail::send($data['to'], $data['subject'], $data['content']);

            // Ö´ÐÐʹÃüÀÖ³É£¬É¾³ýʹÃü
            $job->delete();
        } catch (Exception $e) {
            // Ö´ÐÐʹÃüʧ°Ü£¬ÖØзÅÈëʹÃüÐÐÁÐÖÐ
            // ϵͳ»á×Ô¶¯Ð½¨Ò»¸ö¿ÉÖØÊÔʹÃü²¢·ÅÈëÐÐÁÐ£¬¸ÃʹÃü¿¢ÊºóÖØÐÂʵÑéÖ´ÐÐÄ¿½ñʹÃü
            $job->release(); // »òÕß $job->failed();
        }
    }
}

µÇ¼ºó¸´ÖÆ

2.Ìí¼ÓʹÃüµ½ÐÐÁÐ

ÔÚÐèÒª·¢ËÍÓʼþµÄµØ·½ £¬Í¨¹ýÒÔÏ´úÂ뽫ʹÃüÌí¼Óµ½ÐÐÁÐÖУº

use thinkacadeQueue;

// Ìí¼ÓÒ»ÌõSendMailJobʹÃüµ½ÐÐÁÐÖÐ
Queue::push(new SendMailJob($to, $subject, $content));

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬$to¡¢$subject¡¢$contentΪÓʼþµÄÎüÊÕÕß¡¢Ö÷ÌâºÍÄÚÈÝ¡£

3.ÐÐÁмàÌýÆ÷Ö´ÐÐʹÃü

Æô¶¯ÐÐÁмàÌýÆ÷ºó £¬¾Í»á×Ô¶¯´ÓÐÐÁÐÖÐÈ¡³öʹÃü²¢Ö´ÐС£Ö´ÐÐÀֳɺó £¬Ê¹Ãü»á×ÔÐдÓÐÐÁÐÖÐɾ³ý¡£Ö´ÐÐʧ°Üºó £¬ÐÐÁмàÌýÆ÷»áÖØн«¸ÃʹÃüÍÆÈëÐÐÁÐÖÐ £¬Ö±µ½Ê¹ÃüÖ´ÐÐÀֳɻòµÖ´ï×î´óʵÑé´ÎÊý£¨¿ÉÔÚ.envÎļþÖоÙÐÐÉèÖã©¡£

Èý¡¢½áÓï

±¾ÎÄÏÈÈÝÁËʹÓÃThinkPHP6¾ÙÐÐÓʼþÐÐÁд¦Öóͷ£µÄÒªÁì £¬°üÀ¨×°Öò¢ÉèÖÃÐÐÁÐЧÀÍ¡¢½¨ÉèÓʼþ·¢ËÍʹÃü¡¢Ìí¼ÓʹÃüµ½ÐÐÁкÍÐÐÁмàÌýÆ÷Ö´ÐÐʹÃü¡£Í¨¹ýʹÓÃÓʼþÐÐÁÐ £¬¿ÉÒÔ½«ÓʼþʹÃüÊèÉ¢³öÓ¦ÓóÌÐò £¬Ìá¸ßÐÔÄܺͿɿ¿ÐÔ¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃThinkPHP6¾ÙÐÐÓʼþÐÐÁд¦Öóͷ£ £¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿