PHP code example of masrodjie / codeigniter4-queue
1. Go to this page and download the library: Download masrodjie/codeigniter4-queue library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendEmail implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public function fire($e, $payload) {
$this->onQueue('processing');
echo "FIRE\n";
$email = \Config\Services::email();
$config = [
'protocol' => getenv('EMAIL_PROTOCOL'),
'SMTPUser' => getenv('EMAIL_SMTP_USER'),
'SMTPPass' => getenv('EMAIL_SMTP_PASS'),
'SMTPHost' => getenv('EMAIL_SMTP_HOST'),
'SMTPPort' => getenv('EMAIL_SMTP_PORT'),
'SMTPCrypto' => 'ssl',
'mailType' => 'html',
];
$email->initialize($config);
$email->setFrom('[email protected]', 'John Doe');
$email->setTo($payload['to']);
$email->setSubject('Hello');
$email->setMessage('Hello email');
$email->send();
$e->delete();
}
}
namespace App\Controllers;
class Home extends BaseController
{
public function index()
{
$this->queue->push('\App\Jobs\SendEmail', ['to' => '[email protected]']);
}
}
sh
php spark queue:work
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.