PHP code example of nixphp / queue

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

    

nixphp / queue example snippets


use NixPHP\Queue\QueueJobInterface;

class SendWelcomeEmail implements QueueJobInterface
{
    public function __construct(protected array $payload) {}

    public function execute(): void
    {
        // Send your email here
    }
}

queue()->push(SendWelcomeEmail::class, ['email' => '[email protected]']);

queue('emails')->push(SendWelcomeEmail::class, [
    'email' => '[email protected]'
]);

queue('emails')->pushAndRun(
    SendWelcomeEmail::class,
    ['email' => '[email protected]']
);

use NixPHP\Queue\Core\Queue;
use NixPHP\Queue\Drivers\FileDriver;

app()->container()->set(Queue::class, function () {
    return new Queue(
        new FileDriver(
            app()->getBasePath() . FileDriver::DEFAULT_QUEUE_PATH,
            app()->getBasePath() . FileDriver::DEFAULT_DEADLETTER_PATH
        )
    );
});