尊龙凯时人生就是搏

laravel ÐÐÁÐÔõÑùʹÓÃ

Ëæ×Å»¥ÁªÍøÐÐÒµµÄÒ»Ö±Éú³¤ £¬ÎÒÃǵÄÍøÕ¾Ô½À´Ô½ÖØ´ó £¬»á¼ûÁ¿Ò²Ô½À´Ô½´ó ¡£Ôڸ߲¢·¢µÄÇéÐÎÏ £¬´¦Àí´ó×ڵĺÄʱʹÃüÊÇÒ»ÏîºÜÊǼ¬ÊÖµÄʹÃü £¬»áµ¼ÖÂÎÒÃǵÄÓªÒµ·ºÆ𿨶١¢¹£ÈûµÄÇéÐÎ ¡£ÎªÏàʶ¾öÕâ¸öÎÊÌâ £¬laravelÌṩÁËÐÐÁй¦Ð§ £¬¿ÉÓÃÀ´´¦ÀíһЩÒì²½¿ÉÑÓ³ÙµÄʹÃü £¬ÈÃÓû§²»»á¸ÐÊܵ½Í£Áô ¡£½ÓÏÂÀ´ £¬ÎÒÃǾÍÀ´ÏàʶlaravelÐÐÁÐÔõÑùʹÓà ¡£

Ò»¡¢×°ÖÃÐÐÁÐ

1.×°ÖÃÐÐÁаü

ÔÚLaravelÖÐ £¬ÐÐÁб»°²ÅÅÔÚLaravelÐÐÁÐÊÂÇé°üÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃComposerÀ´×°Öøðü£º

composer require illuminate/queue

2.Ìí¼ÓÐÐÁÐÌṩ³ÌÐò

LaravelÖ§³Ö¶à¸öÐÐÁкó¶Ë £¬°üÀ¨Êý¾Ý¿â¡¢Redis¡¢BeanstalkdµÈ ¡£ÎÒÃÇÐèÒªÔÚconfig/queue.phpÖÐÉèÖÃÐÐÁÐÌṩ³ÌÐò ¡£ÀýÈç £¬ÎÒÃÇ¿ÉÒÔʹÓÃRedisÐÐÁÐÌṩ³ÌÐò£º

‘connections’ => [

'redis' => [
    'driver' => 'redis',
    'connection' => 'default',
    'queue' => 'default',
    'retry_after' => 90,
    'block_for' => null,
],

µÇ¼ºó¸´ÖÆ

],

¶þ¡¢½¨ÉèʹÃü

ÐÐÁб»Éè¼ÆÓÃÀ´´¦Àí³¤Ê±¼äÔËÐеÄʹÃü £¬Õâ¿ÉÒÔÊÇÈκÎʹÃü»òÏÂÁî ¡£ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÁîÐÐÀ´ÌìÉúÒ»¸öеÄÐÐÁÐʹÃü£º

php artisan make:job SendEmail

ÌìÉúµÄÐÐÁÐʹÃüÀà±»°²ÅÅÔÚapp/JobsĿ¼Ï £¬ÊÖ¶¯ÌìÉúµÄSendEmailʹÃüÀàÊÇÒ»¸ö»ù´¡Àà £¬¿´ÆðÀ´ÏñÕâÑù£º

namespace AppJobs;

use IlluminateBusQueueable;

use IlluminateContractsQueueShouldQueue;

use IlluminateFoundationBusDispatchable;

use IlluminateQueueInteractsWithQueue;

use IlluminateQueueSerializesModels;

class SendEmail implements ShouldQueue

{

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct()
{
    //
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    //
}

µÇ¼ºó¸´ÖÆ

}

ÎÒÃÇ¿ÉÒÔÔÚhandle()ÒªÁìÖбàдʹÃüµÄÏêϸʵÏÖÂß¼­ ¡£

Èý¡¢ÍÆËÍʹÃüµ½ÐÐÁÐ

ÔÚLaravelÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃ$dispatch()¾²Ì¬ÒªÁ콫ʹÃü¼ÓÈëÐÐÁÐ ¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷¡¢Â·ÓÉ»òÆäËûÈκεط½Ê¹ÓôËÒªÁì £¬ÈçÏÂËùʾ£º

use AppJobsSendEmail;

SendEmail::dispatch();

ÎÒÃÇÒ²¿ÉÒÔʹÓÃÐÐÁеÄdelay()ºÍonQueue()ÒªÁìÖ¸¶¨ÑÓ³ÙºÍÐÐÁÐÃû³Æ ¡£

ÀýÈç £¬½«Ê¹ÃüÍÆË͵½ÃûΪ”emails”µÄÐÐÁÐ £¬²¢ÔÚ10Ãëºó´¦Àí£º

SendEmail::dispatch()->onQueue(’emails’)->delay(now()->addSeconds(10));

ËÄ¡¢ÔËÐÐÐÐÁÐ

ÎÒÃÇÒѾ­½«Ê¹ÃüÍÆË͵½ÐÐÁÐÖÐ £¬ÏÖÔÚÐèÒªÔËÐÐÐÐÁв¢´¦ÀíʹÃü ¡£ÔÚLaravelÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃArtisanÏÂÁîÀ´Æô¶¯ÐÐÁд¦ÀíÆ÷£º

php artisan queue:work

ĬÈÏÇéÐÎÏ £¬ÐÐÁд¦ÀíÆ÷½«Ê¹ÓÃÃûΪ”default”µÄÐÐÁÐÌṩ³ÌÐò ¡£ÎÒÃÇ¿ÉÒÔͨ¹ýʹÓÔ–queue”Ñ¡ÏîÀ´ÉèÖô¦ÀíÆ÷´¦ÀíµÄÐÐÁÐ ¡£ÀýÈç £¬´¦ÀíÓʼþÐÐÁУº

php artisan queue:work –queue=emails

ÈôÊÇÄãÏ£ÍûʹÓÃËùÓпÉÓõĴ¦ÀíÆ÷ÂÖÁ÷´¦ÀíÐÐÁÐ £¬Ôò¿ÉÒÔʹÓÔ–daemon”Ñ¡Ïî ¡£ÕâÑù¿ÉÒÔÈ·±£×ÝȻһ¸ö´¦ÀíÆ÷¹Òµô £¬Ò²²»»á×èÖ¹´¦ÀíÆ÷µÄÔËÐÐ ¡£

php artisan queue:work –daemon

ÉÐÓÐÆäËûÐí¶àÐÐÁд¦ÀíÆ÷µÄÑ¡Ïî ¡£Äú¿ÉÒÔʹÓÃphp artisan queue:work –helpÏÂÁîÉó²éËùÓÐÑ¡ÏîºÍÏà¹ØÐÅÏ¢ ¡£

Îå¡¢×ܽá

ÒÔÉÏÊÇlaravelÐÐÁеÄʹÓð취 £¬Ê¹ÓÃlaravelÐÐÁÐ £¬ÎÒÃÇ¿ÉÒÔÇáËÉ´¦Àí´ó×ÚºÄʱʹÃü £¬´Ó¶øÌá¸ßÓ¦ÓóÌÐòµÄЧÂʺÍÏìÓ¦ËÙÂÊ ¡£ÈôÊÇÄúÏ£ÍûÉîÈëÏàʶÐÐÁеĸü¶àÄÚÈݺÍÑ¡Ïî £¬ÇëÉó²éLaravel¹Ù·½Îĵµ ¡£

ÒÔÉϾÍÊÇlaravel ÐÐÁÐÔõÑùʹÓõÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

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