PHP queue framework WanQueue file redis queue PHP queue framework WanQueue/file queue, you can quickly switch to any queue such as reids/mysql. Happy/convenient/Simple.
Run php WanQueue/console/QueueServer. php to enable the Queue Service.
// Add a task to the queue
$ Que = new WanQueue \ Queue ();
$ Que-> push (new WanQueue \ Jobs \ Email ('2017 @ 163.com ',' I love wanwan ',' I love you! '));
Usage
Push (new WanQueue \ Jobs \ Email ('2017 @ 163.com ',' I love wanwan ',' I love you! '));
Job example
Email = $ email; $ this-> title = $ title; $ this-> content = $ content;} function handle () {// TODO: Implement handle () method. echo 'email to: ', $ this-> email, 'theme:', $ this-> title, 'Send success! ', "\ N ";}}
Redis driver queue
QueueName = $ queueName; $ this-> getRedisQueue ();}/*** get queue --- redis */private function getRedisQueue () {if ($ this-> queue = null) {try {$ this-> queue = new \ Redis (); $ this-> queue-> pconnect ('123. 0.0.1 ', 6379);} catch (Exception $ e) {file_put_contents (date ('Y-m-D '). '-redis. log', date ('Y-m-d H: I: s '). ':'. $ e-> getMessage (), FILE_APPEND) ;}}/ *** get queue ----- file version */private function getQueue () {$ queue = _ DIR _. "/Queue/{$ this-> queueName}. queue"; if (! Is_file ($ queue) {return [];} return json_decode (file_get_contents ($ queue), true );} /*** queue persistence ---- file version */private function setQueue () {if (! Is_dir (_ DIR __. "/Queue") {mkdir (_ DIR __. "/Queue");} file_put_contents (_ DIR __. "/Queue/{$ this-> queueName }. queue ", json_encode ($ this-> queue);}/*** queue ** @ param $ value * @ return int */function push ($ value) {return $ this-> queue-> rpush ($ this-> queueName, serialize ($ value);}/*** queue ** @ return mixed */function pop () {return unserialize ($ this-> queue-> lpop ($ this-> queueName ));} /*** start to join the queue * @ param $ value * @ return int */function prePush ($ value) {return $ this-> queue-> lpush ($ this-> queueName, serialize ($ value ));} /*** start from the end * @ return mixed */function popL () {return unserialize ($ this-> queue-> rpop ($ this-> queueName ));} /*** save the queue */function _ destruct () {// TODO: Implement _ destruct () method. // $ this-> setQueue ();}}