PHP code example of slims / queue

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

    

slims / queue example snippets


use SLiMS\Queue\Manager as Queue;

Queue::produce('your message/formatter task etc'); // default topic is slims

// or 

Queue::produce('your message/formatter task etc', topic: 'csv_process');

use SLiMS\Queue\Manager as Queue;

Queue::consume(topic: 'slims', callback: function($message){
    // write your code here
});

// with channel name

Queue::setChannel('worker1')->consume(topic: 'slims', callback: function($message){
    // write your code here
});



return [
    'default_handler' => 'database', // change it with yours. e.g : nsq
    'default_topic' => 'slims',
    'handlers' => [
        'database' => [
            'class' => \SLiMS\Queue\Handlers\Database::class,
            'options' => [
                'table' => 'queue',
                'order' => 'asc',
                'sort_by' => 'created_at',
                'delay_per_job' => 5 // in second
            ]
        ],
        /*'nsq' => [
            'class' => your_handler::class,
            'options' => [
                // your options here, such as host etc
            ]
        ]*/
    ]
];
config/queue.php