当前位置:网站首页>Common methods and descriptions of beanstalk

Common methods and descriptions of beanstalk

2022-06-23 13:58:00 Squatting in the corner counting ants

Basics

require "vendor/autoload.php"; // Import components 
use Pheanstalk\Pheanstalk;// Import components 
$ph = new Pheanstalk('127.0.0.1',11301);// Create links 

Maintenance class

1. View the present pheanStalkd State information

$ph->stats()

2. Displays the existing pipeline

$ph->listTubes()

3. see NewUsers Pipeline information

$ph->useTube('NewUsers')->put('test'); 
$ph->useTube('NewUsers')->put('up'); // towards NewUsers Add a... To the pipe up Mission 
print_r($ph->statsTube('NewUsers'));// see NewUsers Pipeline information 

6. View the status of a task in the specified pipeline

$job = $ph->watch('NewUsers')->reserve(); // Take the task out of the pipeline ( consumption )
print_r($ph->statsJob($job)); // View the status of a task in the specified pipeline 

7. View tasks id by 1 Mission details for

$job = $ph->peek(1);// Take out the task directly id by 1 The task of  [ notes :beanstalkd For all tasks in id They are all unique ] 
print_r($ph->statsJob($job));// View tasks id by 1 Mission details for 

Production

The first one is put()

$tube = $ph->useTube('NewUsers');// Connect NewUsers The Conduit 
print_r($tube->put('four'));// towards NewUsers Pipeline add task four, And return the result 

notes : put() There are ways 3 Optional parameters ( In turn : priority priority, Delay time delay, Task timeout resend ttr)

The second kind putInTube() [ notes : putInTube() That's right useTube() and put() Encapsulation ]

$res = $ph->putInTube('NewUsers','three');// towards NewUsers Pipeline add task three

notes : putInTube() There are ways 3 Optional parameters ( In turn : priority priority, Delay time delay, Task timeout resend ttr)
print_r($res);// Back to task id

print_r($ph->statsTube('NewUsers'));// see NewUsers Details of the pipeline 

Consumer

1.watch monitor NewUsers The Conduit [ notes : watch() You can also listen to multiple pipelines ]

$tube = $ph->watch('NewUsers');
print_r($ph->listTubesWatched());// Print the pipeline that has been monitored 

2.watch Listening to multiple pipes

$tube = $ph->watch('NewUsers')->watch('default');
print_r($ph->listTubesWatched());// Print the pipeline that has been monitored 

3.ignore monitor NewUsers The Conduit , Ignore default The Conduit

$tube = $ph->watch('NewUsers')->ignore('default');
print_r($ph->listTubesWatched());// Print the pipeline that has been monitored 

4.reserve monitor NewUsers The Conduit , And take out the task

$job = $ph->watch('NewUsers')->reserve();
$job = $ph->reserveWithTimeout (3);// Expiration time   second 
var_dump($job);// Print the tasks that have been taken out 
$ph->delete($job);// Delete the removed task 

notes :reserve() Yes 1 Parameters , Blocking time , After the blocking time , Whether there is anything or not , Go straight back to .4.0 After version, it is basically abandoned , Change it to reserveWithTimeout (3)

5.putInTube/put towards NewUsers Pipeline write task [ notes : This is the producer method , Put here for easy understanding ]

$ph->putInTube('NewUsers','number_1',5);
$ph->putInTube('NewUsers','number_2',3);
$ph->putInTube('NewUsers','number_3',0);
$ph->putInTube('NewUsers','number_4',4);
print_r($ph->statsTube('NewUsers'));// see NewUsers Pipe details 

6.release Put the removed task back ready state , also 2 Parameters ( Priority and delay )

$job = $ph->watch('NewUsers')->reserve();// monitor NewUsers The Conduit , And take out the task 
if (true) {
    sleep(30);
    $ph->release($job);// After taking the task out , Stop 30 second , Then change the task status back to ready
} else {
    $ph->delete($job);
}


7.bury ( reserve ) After taking the task out , It is found that the logic executed later is not mature ( E-mail , I suddenly found that the mail server was down ), In other words, the following logic cannot be executed , The task needs to be sealed up first , Waiting for the time to come , Then take out this task for consumption

$job = $ph->watch('NewUsers')->reserve();// Take out the task 
$ph->bury($job);// After taking out the task , Put the task aside ( reserve )

8.peekBuried() Will be in bury The status of the task is read out

$job = $ph->peekBuried('NewUsers');// take NewUsers In the pipeline bury The status of the task is read out 
var_dump($ph->statsJob($job));// Print job status ( The task status should be bury)

9.kickJob() Will be in bury The task in task status is converted to ready state

$job = $ph->peekBuried('NewUsers');// take NewUsers In the pipeline bury The status of the task is read out 
$ph->kickJob($job);

10.kick()   Will be in bury The task in task status is converted to ready state , There's a second parameter int, Batch tasks id Tasks less than this number are converted to ready

$ph->useTube('NewUsers')->kick(65);// hold NewUsers Tasks in the pipeline id Less than 65, And the task status is bury All the tasks of are transformed into ready

11.peekReady() Place the ready The status of the task is read out

$job = $ph->peekReady('NewUser');// take NewUser In the pipeline, there is ready The status of the task is read out 
var_dump($job);
$ph->delete($job);

12.peekDelay() Place all in the pipe at delay The status of the task is read out

$job = $ph->peekDelayed('NewUser');
var_dump($job);
$ph->delete($job);

13.pauseTube() Set the delay for the entire pipeline , Leave the pipeline in a delayed state

$ph->pauseTube('NewUser',10);// Set up pipes NewUser The delay time is 10s
$job = $ph->watch('NewUser')->reserve();// monitor NewUser The Conduit , And take out the task 
var_dump($job);

14.resumeTube() Restore pipeline , Leave the pipeline in a non delayed state , Be consumed immediately

$ph->resumeTube('NewUser');// Cancel pipeline NewUser Delay state of , Change to read immediately 
$job = $ph->watch('NewUser')->reserve();// monitor NewUser The Conduit , And take out the task 
var_dump($job);

15.touch() Let task recalculate task timeout resend ttr Time , It is equivalent to prolonging the life of the task
 

原网站

版权声明
本文为[Squatting in the corner counting ants]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230943589671.html