PHP code example of huuuk / phalcon-queues

1. Go to this page and download the library: Download huuuk/phalcon-queues 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/ */

    

huuuk / phalcon-queues example snippets


use Huuuk\Queues\QueueManager;

// other services

$queueManager = new QueueManager($config);
$di->set('queue', $queueManager->getQueue());



class QueueTask extends \Huuuk\Queues\QueueTask
{
    
}

// where di it's your DI instance
$di->getQueue()->push(function() {
    // do yuor magic
    });

// where di it's your DI instance
$di->getQueue()->push(function($di) {
    $di->getMailer()->send($address);
    });

// app/config/services.php
$di->set('mailer', '\SomeNamespace\SomeClassName');

$di->getQueue()->push(function($di) {
    $di->getMailer()->send($address);
    });

// app/cli
$di->set('mailer', '\SomeNamespace\SomeClassName');

$user = User::findFirstById($id);
$di->getQueue()->push(function($di) use($user) {
    $user->sendNotification();
    });

use Huuuk\Queues\Job;

class SendMail extends Job
{
    protected $address;
    
    function __construct($address)
    {
        $this->$address = $address;
    }

    public function handle()
    {
        // Place here yor logic
        // to access DI, call
        // $this->getDi();
        $this->getDi()->getMailer()->send($this->address);
    }
}

$user = User::findFirstById($id);
$job = new SendMail($user->email);
$di->getQueue()->push($job);

$di->getQueue()->push(new SimpleJob); // queue name = 'default'
$di->getQueue()->push(new SimpleJob, null); // queue name = 'default'
$di->getQueue()->push(new SenDMail, 'mail');
$di->getQueue()->push(new ImageResize, 'images');

$di->getQueue()->push(new SimpleJob, null, 30); //  no earlier than 30 seconds
$di->getQueue()->push(new SenDMail, 'mail', 60*60); //  no earlier than 30 seconds an hour
$di->getQueue()->push(new ImageResize, 'images'); // as soon as worker will be run
bash
php app/cli queue help
bash
php app/cli queue dbtable --create
# for a bit more info run
# php app/cli queue --help
bash
php app/cli queue work
bash
php app/cli queue help