PHP code example of masrodjie / codeigniter3-queue
1. Go to this page and download the library: Download masrodjie/codeigniter3-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/ */
masrodjie / codeigniter3-queue example snippets
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";
$ci=&get_instance();
$ci->load->library('email');
$ci->email->from('[email protected]', 'Your Name');
$ci->email->to($payload['to']);
$ci->email->subject('Email Test');
$ci->email->message('Testing the email class.');
$ci->email->send();
$e->delete();
}
}
if(!defined('BASEPATH')) exit('No direct access script allowed');
class Queue extends CI_Controller {
public function work() {
$queue = new Masrodjie\Queue\Libraries\Queue();
$dispatcher = new Illuminate\Events\Dispatcher();
$exception = new \Masrodjie\Queue\Exceptions\Handler();
$isDownForMaintenance = function () {
return false;
};
$worker = new Illuminate\Queue\Worker($queue->getQueueManager(), $dispatcher, $exception, $isDownForMaintenance, null);
$options = new Illuminate\Queue\WorkerOptions();
$options->maxTries = 5;
$options->timeOut = 300;
$worker->daemon('redis', 'default', $options);
}
}
if(!defined('BASEPATH')) exit('No direct access script allowed');
class Test extends CI_Controller {
{
public function index()
{
$queue = new Masrodjie\Queue\Libraries\Queue();
$queue->push('\App\Jobs\SendEmail', ['to' => '[email protected]']);
}
}
sh
composer dump-autoload
sh
php index.php 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.