PHP code example of bupy7 / zf-queue

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

    

bupy7 / zf-queue example snippets


// YourModule/src/task/ExampleTask.php

namespace YourModule\Task;

use Bupy7\Queue\Task\TaskInterface;
use Laminas\Stdlib\ParametersInterface;
use Chat\Service\ChatService;

class SendAccountTask implements TaskInterface
{
    /**
     * @var ChatService
     */
    protected $chatService;

    public function __construct(ChatService $chatService) {
        $this->chatService = $chatService;
    }

    /**
     * @param ParametersInterface $params
     * - message (string)
     * @return bool
     */
    public function execute(ParametersInterface $params): bool
    {
        $this->chatService->send($params->get('message'));
        return true;
    }
}

// YouModule/config/queue.config.php

namespace YourModule;

return [
    'queue_manager' => [
        'factories' => [
            Task\ExampleTask::class => \Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class,
        ],
    ],
];

// YourModule/src/YourModule.php

class Module
{
    public function getConfig(): array
    {
        return array_merge(
            
            // another config files
            
            

$container->get('Bupy7\Queue\Service\QueueService')->add('YourModule\Task\ExampleTask');

$container->get('Bupy7\Queue\Service\QueueService')->run();

$ php composer.phar