search

PHP-Resque usage

Jun 06, 2020 am 11:03 AM
php

PHP-Resque usage

PHP-Resque Usage

PHP-Resque is an extension library for PHP for Resque, which enables PHP to use Resque. Resque is A background process system developed based on Redis. Compared with other Queue systems, Resque's design is very simple and fully utilizes the characteristics of Redis.

1. Install php-resque

Enter the project root directory, composer install php-resque

composer require chrisboulton/php-resque

2. Common methods

1. Connect to redis

// setBackend($server, $database = 0)
Resque::setBackend('127.0.0.1:6379');

2. Add work to the queue

// enqueue($queue, $class, $args = null, $trackStatus = false)
$token = Resque::enqueue('default', 'My_Job', ['name'=>'test'], true);

3. Check the work status

$status = (new Resque_Job_Status($token))->get();

4. Stop (remove) the job

(new Resque_Job_Status($token))->stop();

3. Resident task processing queue (example: worker.php)

// 处理 default 队列;也可以填 *,代表所有队列
$worker = new Resque_Worker('default');
// LOG_NONE 不写日志, LOG_NORMAL 普通,LOG_VERBOSE 详细
$worker->logLevel = Resque_Worker::LOG_VERBOSE;
// 队列处理时间间隔,单位:秒
$worker->work(5);

Note: worker.php must be executed through the command line and resides in the background, /usr/local/php/bin/php /xxx/xxx/worker.php

4. Classes for processing work

class My_Job
{
    /**
     * 前置操作
     * @return void
     */
    public function setUp()
    {
        // ... Set up environment for this job
    }
    /**
     * 消费队列
     * @return void
     */
    public function perform()
    {
        // execute a job
    }
    /**
     * 后置操作
     * @return void
     */
    public function tearDown()
    {
        // ... Remove environment for this job
    }
}

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of PHP-Resque usage. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function