һЩ³£¼ûµÄLaravel׼ʱʹÃü²»ÔËÐеÄÎÊÌâ
Ëæ×ÅÏÖ´ú»¥ÁªÍø¼°Ó¦ÓóÌÐòµÄÒ»Ö±Éú³¤£¬Ðí¶à³ÌÐòÔ±×îÏÈʹÓÃlaravel×÷Ϊ×Ô¼ºµÄ¿ò¼Ü¡£laravel¿ò¼ÜÖÐÌṩµÄ׼ʱʹÃü¹¦Ð§£¬¿ÉÒÔͨ¹ý¼òÆÓµÄÉèÖÃÀ´×Ô¶¯Ö´ÐÐһЩʹÃü¡£¿ÉÊÇ£¬ÓÐʱ¼äÎÒÃǻᷢÃ÷ÕâЩ׼ʱʹÃü²¢Ã»ÓÐƾ֤ÎÒÃǵÄÔ¤ÆÚÀ´ÔËÐУ¬Õâʱ¼ä¸ÃÔõô°ìÄØ£¿
ÔÚ±¾ÆªÎÄÕÂÖУ¬ÎÒÃǽ«Ì½ÌÖһЩ³£¼ûµÄLaravel׼ʱʹÃü²»ÔËÐеÄÎÊÌ⣬²¢ÌṩÏìÓ¦µÄ½â¾ö¼Æ»®¡£
¼ì²é׼ʱʹÃüÉèÖÃ
Ê×ÏÈ£¬ÎÒÃÇÐèÒª¼ì²éÎÒÃǵÄ׼ʱʹÃüÊÇ·ñÒѾÉèÖÃ׼ȷ¡£ÔÚLaravel¿ò¼ÜÖÐÉèÖÃ׼ʱʹÃüºÜÊǼòÆÓ£¬Ö»ÐèÔÚapp/Console/Kernel.phpÎļþÖнç˵һ¸öscheduleÒªÁì¼´¿É¡£scheduleÒªÁì°üÀ¨ÁËÎÒÃÇÒªÔËÐеÄËùÓÐʹÃü£¬ÈçÏÂËùʾ£º
protected function schedule(Schedule $schedule) { $schedule->command('email:send')->daily(); $schedule->command('email:send --force')->hourly(); }
µÇ¼ºó¸´ÖÆ
×¢ÖØ£¬´Ë´¦µÄÏÂÁîemail:send´ú±íÎÒÃÇÒªÔËÐеÄÏêϸʹÃü¡£ÈôÊÇÎÒÃǵÄ׼ʱʹÃüÉèÖÃ׼ȷ£¬¿ÉÊÇ׼ʱʹÃüÒÀÈ»ÎÞ·¨ÔËÐУ¬ÄÇôÎÒÃÇ¿ÉÒÔ˼Á¿¼ì²éÒÔϼ¸¸ö·½Ã棺
¼ì²éϵͳʱ¼ä
Laravel׼ʱʹÃüÊÇÒÀÀµÏµÍ³Ê±¼äµÄ£¬ÈôÊÇϵͳʱ¼ä²»×¼È·£¬ÄÇô׼ʱʹÃü¾Í¿ÉÄÜÎÞ·¨×¼Ê±ÔËÐС£Òò´Ë£¬ÎÒÃÇÐèÒª¼ì²éϵͳʱ¼äÊÇ·ñ׼ȷ¡£
ÈôÊÇÎÒÃÇʹÓÃLinux²Ù×÷ϵͳ£¬ÔÚÖÕ¶ËÊäÈëÒÔÏÂÏÂÁî¿ÉÒÔÉó²éÄ¿½ñµÄϵͳʱ¼ä£º
$ date
µÇ¼ºó¸´ÖÆ
ÈôÊÇÎÒÃÇʹÓÃWindows²Ù×÷ϵͳ£¬ÔÚÏÂÁîÌáÐÑ·ûÖÐÊäÈëÒÔÏÂÏÂÁî¿ÉÒÔÉó²éÄ¿½ñµÄϵͳʱ¼ä£º
> time/T > date/T
µÇ¼ºó¸´ÖÆ
ÈôÊÇϵͳʱ¼ä²»×¼È·£¬ÎÒÃÇÐèÒªÊÖ¶¯ÉèÖÃ׼ȷʱ¼ä¡£
¼ì²é׼ʱʹÃüÔËÐÐÓû§È¨ÏÞ
Laravel׼ʱʹÃüĬÈÏÊÇÒÔÄ¿½ñÉÏ°¶Óû§µÄȨÏÞÀ´Ö´Ðеġ£ÈôÊÇÄ¿½ñÉÏ°¶Óû§È¨ÏÞȱ·¦£¬×¼Ê±Ê¹Ãü¾Í¿ÉÄÜÎÞ·¨Õý³£ÔËÐС£Òò´Ë£¬ÎÒÃÇÐèÒª¼ì²é׼ʱʹÃüÔËÐеÄÓû§È¨ÏÞÊÇ·ñ×ã¹»¡£
¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉó²éÄ¿½ñÓû§£º
$ whoami
µÇ¼ºó¸´ÖÆ
ÈôÊÇÄ¿½ñÓû§È¨ÏÞȱ·¦£¬ÎÒÃÇ¿ÉÒÔʵÑéʹÓÃsudoÏÂÁîÀ´ÔËÐÐLaravel׼ʱʹÃü£º
$ sudo php artisan schedule:run
µÇ¼ºó¸´ÖÆ
×¢ÖØ£¬ÎÒÃÇÐèÒª¾ßÓÐÖÎÀíԱȨÏ޲ŻªÊ¹ÓÃsudoÏÂÁî¡£
¼ì²éʹÃüÊÇ·ñ±»Ëø¶¨
Laravel׼ʱʹÃüµÄĬÈÏ»úÖÆÊÇÔÚÒ»¸öʹÃüÔËÐеÄʱ¼ä»áÏȸøÕâ¸öʹÃü¼ÓÉÏÒ»°ÑËø£¬±ÜÃâÖظ´ÔËÐС£ÈôÊÇÄ¿½ñʹÃü»¹Ã»ÓÐÔËÐÐÍê±Ï£¬ÄÇô¾ÍÎÞ·¨Æô¶¯ÐµÄʹÃü¡£Õâʱ¼äÎÒÃÇÐèÒª¼ì²éÒÔÏÂÁ½ÖÖÇéÐΣº
ʹÃüËø׼ʱ¼ä¹ý³¤£ºÈôÊÇÎÒÃǵÄʹÃüÔËÐÐʱ¼ä¹ý³¤£¬¾ÍÓпÉÄܵ¼ÖÂʹÃüËø׼ʱ¼ä¹ý³¤£¬Õâʱ¼äÎÒÃÇÐèÒªµ÷½âËø׼ʱ¼ä¡£
ʹÃüûÓÐÕý³£¿¢Ê£ºÈôÊÇÎÒÃǵÄʹÃüÒì³£ÖÕÖ¹£¬Ò²»áµ¼ÖÂʹÃüËø¶¨¡£´ËʱÎÒÃÇ¿ÉÒÔͨ¹ýÉó²éÈÕÖ¾ÎļþÀ´ÕÒµ½ÎÊÌâ²¢½â¾öËü¡£
¼ì²é׼ʱʹÃüÊÇ·ñÆôÓÃ
×îºó£¬ÎÒÃÇÐèÒª¼ì²é׼ʱʹÃüÊÇ·ñÆôÓá£ÓÐЩ׼ʱʹÃü¿ÉÄÜÊÇ¿ÉÒÔÊÖ¶¯¿ØÖÆÊÇ·ñ¿ªÆôµÄ£¬ÎÒÃÇÐèÒª¼ì²éÊÇ·ñÒѾÆôÓá£
ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´Éó²éËùÓеÄ׼ʱʹÃü£º
$ crontab -l
µÇ¼ºó¸´ÖÆ
ÈôÊÇ׼ʱʹÃüûÓÐÔÚÁбíÖÐÏÔʾ£¬ÎÒÃÇÐèÒªÊÖ¶¯½«ÆäÌí¼Óµ½×¼Ê±Ê¹ÃüÁбíÖС£
×ܽá
ÔÚLaravel¿ò¼ÜÖУ¬Ê¹ÓÃ׼ʱʹÃü¿ÉÒÔÇáËÉʵÏÖ×Ô¶¯Ö´ÐÐһЩʹÃü¡£¿ÉÊÇ£¬ÔÚÏÖʵ¿ª·¢Àú³ÌÖУ¬ÎÒÃÇ¿ÉÄÜ»áÓöµ½×¼Ê±Ê¹Ãü²»ÔËÐеÄÎÊÌâ¡£±¾ÎÄÕë¶ÔÕâ¸öÎÊÌâÌṩÁËһЩ³£¼ûµÄ½â¾ö¼Æ»®£¬×ÊÖúÎÒÃǸüºÃµØʹÓÃLaravel¿ò¼ÜÖеÄ׼ʱʹÃü¡£
ÒÔÉϾÍÊÇһЩ³£¼ûµÄLaravel׼ʱʹÃü²»ÔËÐеÄÎÊÌâµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡