TP framework Queue queue usage

First install the queue using the command

composer require topthink/think-queue


Find queue.php (default in config)

Set the queue execution location by yourself, (personally recommend redis)


Queue restart command php think queue:restart 
queue execution command php think queue:work 


Create a queue method in your favorite location


Statements that call queue methods 

\queue('queue file path@method name', the parameters you want to pass (can be an array), how long to delay execution (0 means immediate execution), queue name);

Note: The class name of the queue file path should be capitalized, otherwise the file will not be found


After the execution of the queue method is completed, the task needs to be cleared, otherwise it will be executed repeatedly

$job->delete();

If the execution of the queue is unsuccessful, the re-execution method can be used to re-execute the queue (the parameter is to re-execute after a few seconds)

$job->release(2);

Note: Once the queue method is modified, the queue service needs to be restarted to take effect.

Guess you like

Origin blog.csdn.net/echozly/article/details/122467334