简体   繁体   English

当我使用 linux 时,为什么 laravel 上的 Jobs 会导致我的计算机崩溃? 但是当我使用 Windows 时工作正常?

[英]Why Jobs on laravel crashes my computer when I'm using linux? but works fine when I'm using Windows?

I have been a laravel developer for 1 year already..Before I used laravel on Windows but since I use Linux..I have a Big problem on Jobs in laravel..every time I start a Job on linux my machine crashes.. but on windows everything works fine.我已经是 1 年的 laravel 开发人员了..在我在 Windows 上使用 laravel 之前,但自从我使用 Linux 之后..我在 laravel 中的 Jobs 上遇到了一个大问题..每次我在 linux 上开始工作时,我的机器都会崩溃.. 但是在 Windows 上一切正常。

//my Controller //我的控制器

<?php

namespace App\Http\Controllers;
use App\Jobs\CustomerJob;

use Illuminate\Http\Request;

class SendEmailControllers extends Controller
{
public function sendEmail(){
    dispatch(new CustomerJob())->delay(now()->addMinutes(1));
    dd('Email has been delivered');
}

} }

//Job Code //职位代码

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeUserMail;

class CustomerJob 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()
{
    Mail::to('bramslevel129@gmail.com')->send(new WelcomeUserMail);
}

} }

Here is the error that is displayed when I restart the machine.这是我重新启动机器时显示的错误。 the error is displayed on my Failed_job table..错误显示在我的 Failed_job 表上。

//error //错误

Illuminate\Queue\MaxAttemptsExceededException: 
App\Jobs\CustomerJob has been attempted too many times or run too long.
The job may have previously timed out.
in /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:750 Stack trace:#0 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(504): Illuminate\Queue\Worker->maxAttemptsExceededException()
#1 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(418): Illuminate\Queue\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts()
#2 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\Queue\Worker->process()
#3 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(172): Illuminate\Queue\Worker->runJob()
#4 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(126): Illuminate\Queue\Worker->daemon()
#5 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(110): Illuminate\Queue\Console\WorkCommand->runWorker()
#6 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle()
#7 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#8 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#9 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#10 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call()
#11 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#12 /home/dev/www/laravel-authentication/vendor/symfony/console/Command/Command.php(291): Illuminate\Console\Command->execute()
#13 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#14 /home/dev/www/laravel-authentication/vendor/symfony/console/Application.php(989): Illuminate\Console\Command->run()
#15 /home/dev/www/laravel-authentication/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#16 /home/dev/www/laravel-authentication/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#17 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Console/Application.php(102): Symfony\Component\Console\Application->run()
#18 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#19 /home/dev/www/laravel-authentication/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#20 {main}

try set breaking rules for job to stop hanging your system尝试为作业设置破坏规则以停止挂起您的系统

//CustomerJob.php
    /**
     * The number of seconds the job can run before timing out.
     *
     * @var int
     */
    public $timeout = 15; // just for your case

    /**
     * Indicate if the job should be marked as failed on timeout.
     *
     * @var bool
     */
    public $failOnTimeout = true;


    /**
     * The number of times the job may be attempted.
     *
     * @var int
     */
    public $tries = 3;
 
    /**
     * The maximum number of unhandled exceptions to allow before failing.
     *
     * @var int
     */
    public $maxExceptions = 1;

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::debug('jobs', ['job start']);
        Mail::to('bramslevel129@gmail.com')->send(new WelcomeUserMail);
        Log::debug('jobs', ['job end']);
    }

and check project_folder/storage/logs/laravel.log (if log configured as single file) or corresponding with log config - there can be errors regarding job itself not (failed to send mail because of bad mail config for example)并检查project_folder/storage/logs/laravel.log (如果日志配置为单个文件)或对应于日志配置 - 可能存在关于作业本身的错误(例如,由于错误的邮件配置而无法发送邮件)


step 2: try set mail driver to log to see changes and again check logs第 2 步:尝试将邮件驱动程序设置为记录以查看更改并再次检查日志

# .env file
# you can comment lines using # in this file
# MAIL_MAILER=smtp
MAIL_MAILER=log
MAIL_LOG_CHANNEL=debug

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Linux时没有JAVA声音控制吗? - No JAVA sound control when I'm using Linux? Python脚本可以在Linux上运行,但不能在Windows上运行,我真的很绝望 - Python script works on linux but not on windows, I'm really desperate 在Linux上通过Windows身份验证访问WSO2身份服务器时,出现登录提示和警告 - I'm getting a login prompt and warning when accessing my WSO2 Identity Server via Windows Authentication on Linux 为什么在使用Files.copy()在linux中复制文件时出现NoSuchFileException。 但是在Windows中可以正常工作。 - Why am I Getting NoSuchFileException while copying a file in linux using Files.copy(). But works fine in windows. 我的程序在Windows机器上崩溃,但在Linux上运行正常 - My program crashes on the Windows machine yet it works fine on the Linux 如何使用scp将文件从远程计算机(运行Linux)复制到Windows计算机? - How do I copy files from a remote computer (running Linux) to my Windows computer using scp? 为什么这个C程序在Windows上崩溃并且在linux上工作正常? - Why is this C program crashes on windows and works fine on linux? 为什么我没有使用的技术在我的 AWS 服务器上 - Why technologies I'm not using is on my AWS server 尝试推送到Linux AWS服务器上的裸仓库时出现“权限不足...”错误 - I'm getting a 'insufficient permission…' error when trying to push to my bare repo on my linux AWS server 使用“python3 -m http.server 8080”时如何进入我的桌面? - How to I get to my desktop when using "python3 -m http.server 8080"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM