menu

Questions & Answers

I can't show echo result using queues

I initially tried using the code without queues and it worked fine. Since the execution took a long time to get the results I tried for my first time to use the queues.

These are the steps I did:

Route:

Route::get('/getemail', [Controller::class, 'mail'])->name('email.get');

Controller:

public function mail()
    {
        dispatch((new SendEmail()));
    }

JOB: SendEmail

public function __construct()
    {
        //
    }


 public function handle()
    {
        $oClient = EmailClient::account('default');
        $oClient->connect();
        $folders = $oClient->getFolders("INBOX")->first();
        $fatture = Invoice::all();
        $messages = $folders->query()->since(now()->subDays(300))->get();

        foreach ($messages as $message) {
            if (str_contains($message->getSubject(), "Ricevuta")) {
                //dd($message->getRawBody());
                $value = strstr($message->getRawBody(), "<NomeFile>");

                $result = substr($value, 10, 24);
                //echo $result .  "<br>";
                foreach ($fatture as $fattura) {
                    if ($fattura->nome_file == $result) {
                        echo $result . "<br>";
                    }
                }
            }
        }

    }

In particular, I want to retrieve some information from each email.

Since I display the results with echo, I notice that a blank page with no content is shown to me.

Since this is my first time using queues, can someone kindly tell me where is the problem please??

Thank you all!!!

Comments:
2023-01-18 23:30:03
You can't echo, print_r or anything similar on queues... the only way to see that would be on the queue worker (php artisan queue:work), but when you are on production, that command is usually being run by supervisord, so you will not want to output anything.... You have to store whatever you want in logs or a database or anything else, but with Laravel you do not echo anymore
2023-01-18 23:30:03
@matiaslauriti ok i didn't know about this. How can I show $result? What do you suggest me? I would also like to have an answer and understand it
2023-01-18 23:30:03
i have already previously tried to do php artisan queue:work and i get DONE
Answers(1) :

Your route not properly define.

Route::get('/getemail', [ControllerName::class, 'mail'])->name('email.get');

Add controller dependency