PHP code example of softwarepunt / php-resque

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

    

softwarepunt / php-resque example snippets


Resque::setBackend('localhost:6379');

namespace MyApp;

class Greeter_Job
{
    public function setUp()
    {
        // Optional: Set up before (called before perform())
    }

    public function perform()
    {
        // Required: Main work method
        
        // Perform work; context data is accessible from $this->args
        echo "Hello, {$this->args['name']}!";
    }
    
    public function tearDown()
    {
        // Optional: Tear down after (called after job finishes)
    }
}

// Enqueue an instance of "My_Job" in the "default" queue
Resque::enqueue('default', 'MyApp\Greeter_Job', ['name' => "Hank"]);

// Remove all jobs of a certain type from a queue
Resque::dequeue('default', ['MyApp\Greeter_Job']);

// Remove specific job from a queue
Resque::dequeue('default', ['MyApp\Greeter_Job' => '087df5819a790ac666c9608e2234b21e']);

QUEUE=default php vendor/bin/resque

Resque_Event::listen('eventName', $callback);

public function perform()
{
    echo $this->queue; // my_queue (Queue name)
    echo $this->job->payload['id']; // aa4c8b768d7b89a1b90d000cfefdf785 (Job ID)
    echo $this->job->payload['queue_time']; // 1695993877.3551 (Job enqueued at)
}
bash
composer