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!!!
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 php artisan queue:work
and i get DONE Your route not properly define.
Route::get('/getemail', [ControllerName::class, 'mail'])->name('email.get');
Add controller dependency