php-resque实战

环境安装

安装REDIS

brew install redis
brew install homebrew/php/php71-redis

安装PHP-RESQUE

{    
    "require": {        
        "chrisboulton/php-resque": "1.2.x"
    }
}

composer install


代码封装

推送任务

require_once 'vendor/autoload.php';
date_default_timezone_set('GMT');
Resque::setBackend('127.0.0.1:6379');

$args = array(
   'time' => time(),
   'array' => array(
       'name' => 'Task_1',
       'todo' => 'add'
   ),
);

$jobId = Resque::enqueue('Task', 'Task', $args, true);
echo "Queued job ".$jobId."\n\n";

任务类

require_once 'vendor/autoload.php';
use redis\redis;

class Task
{
   public function perform()
   {
       $redis = new Redis('127.0.0.1','',6379);
       $redis-> set('Task_1', json_encode($this->args));
   }
}

服务类


include 'job/Task.php';

$queues = explode(',', 'Task');
$worker = new \Resque_Worker($queues);

fwrite(STDOUT, '*** Starting worker '.$worker."\n");
$ret = (string)$worker->work(1);
fwrite(STDOUT, $ret);


使用

添加任务

wuzhens-MacBook-Pro:bdmain wuzheng40$ php Starttask.php 
Queued job dc84f77630a825dbac801699c6c8f82a
Queued job 38a3874f1739cf614170769e7b38fc53

启动服务

wuzhens-MacBook-Pro:bdmain wuzheng40$ QUEUE=* php Server.php 
*** Starting worker wuzhens-MacBook-Pro.local:72678:Task

REDIS

127.0.0.1:6379> keys *
1) "resque:workers"
2) "Task_1"
3) "resque:queues"
4) "resque:worker:wuzhens-MacBook-Pro.local:72678:Task:started"
5) "resque:stat:processed"
6) "resque:stat:processed:wuzhens-MacBook-Pro.local:72678:Task"
7) "Task_2"
8) "resque:job:38a3874f1739cf614170769e7b38fc53:status"
9) "resque:job:dc84f77630a825dbac801699c6c8f82a:status"
127.0.0.1:6379> get Task_1
"{\"time\":1513307784,\"array\":{\"name\":\"Task_1\",\"todo\":\"add\"}}"
127.0.0.1:6379> get Task_2
"{\"time\":1513307784,\"array\":{\"name\":\"Task_2\",\"todo\":\"lock\"}}"


GITHUB

https://github.com/chrisboulton/php-resque






birkin bag

2017-12-31 18:58:01

I would like to express some thanks to you just for bailing me out of this particular condition. Because of surfing around throughout the the web and coming across things which were not powerful, I believed my life was well over. Living without the presence of approaches to the issues you have solved all through your short article is a critical case, as well as ones that could have adversely damaged my career if I had not noticed your web page. Your main expertise and kindness in playing with everything was excellent. I am not sure what I would've done if I hadn't come upon such a thing like this. It's possible to now look forward to my future. Thanks a lot so much for your specialized and results-oriented help. I won't be reluctant to recommend your site to anybody who should get guidelines about this subject.

adidas ultra boost

2017-12-31 20:56:27

An interesting discussion is value comment. I feel that you must write extra on this subject, it might not be a taboo subject but usually individuals are not sufficient to speak on such topics. To the next. Cheers

converse shoes

2018-01-01 23:39:49

I have to express some appreciation to you for bailing me out of such a matter. Just after scouting throughout the the net and obtaining concepts which were not powerful, I assumed my life was over. Living without the approaches to the difficulties you've fixed by means of the blog post is a critical case, as well as the kind that might have in a wrong way damaged my career if I hadn't encountered the blog. Your personal mastery and kindness in controlling a lot of things was valuable. I don't know what I would have done if I had not encountered such a solution like this. I'm able to now relish my future. Thanks for your time so much for the high quality and result oriented help. I won't be reluctant to endorse your blog post to any individual who requires care about this matter.

yeezy boost

2018-01-03 03:38:48

Needed to put you this tiny observation in order to thank you so much again about the lovely pointers you have documented on this site. It was so extremely generous of people like you to offer easily just what a number of people could have sold as an e-book to earn some money for themselves, certainly since you might well have done it if you wanted. These basics in addition served to become easy way to fully grasp that most people have the identical dreams much like my very own to find out a good deal more with respect to this condition. I'm certain there are several more pleasurable sessions in the future for folks who take a look at your website.

yeezy boost

2018-01-03 06:36:50

You made some first rate points there. I regarded on the web for the issue and located most individuals will associate with along with your website.

light up shoes

2018-01-04 12:30:34

I enjoy you because of all your labor on this web page. My mother loves participating in internet research and it is simple to grasp why. We all learn all regarding the powerful means you render precious guidance on your web site and even strongly encourage participation from visitors on that concept then our princess has been becoming educated a lot of things. Have fun with the remaining portion of the new year. You have been carrying out a great job.

jordan 4

2018-01-06 00:48:19

I am commenting to make you know of the fantastic discovery my friend's girl enjoyed browsing your webblog. She discovered so many issues, which included what it's like to have an ideal coaching style to get other individuals quite simply understand some grueling issues. You really surpassed people's expected results. Thank you for displaying such warm and helpful, trustworthy, explanatory and even unique guidance on this topic to Evelyn.

nmd

2018-01-06 04:41:31

There are certainly a number of particulars like that to take into consideration. That may be a great point to bring up. I offer the ideas above as common inspiration but clearly there are questions just like the one you carry up where the most important thing can be working in trustworthy good faith. I don?t know if greatest practices have emerged around issues like that, but I am certain that your job is clearly recognized as a fair game. Each girls and boys really feel the impression of just a second抯 pleasure, for the rest of their lives.

Aw, this was a really nice post. In idea I want to put in writing like this additionally ?taking time and precise effort to make an excellent article?but what can I say?I procrastinate alot and under no circumstances appear to get something done.

asics sneakers

2018-01-07 19:45:06

I am writing to make you be aware of what a impressive discovery my daughter went through reading through your blog. She came to understand some issues, with the inclusion of what it's like to have a very effective coaching mindset to let most people without hassle comprehend certain complicated matters. You undoubtedly did more than people's expectations. Many thanks for distributing such useful, healthy, explanatory as well as cool tips about this topic to Sandra.

nmd

2018-01-07 23:00:49

I want to show my thanks to you for rescuing me from such a trouble. After surfing throughout the world-wide-web and finding suggestions which were not beneficial, I believed my entire life was well over. Being alive minus the answers to the difficulties you have fixed all through this website is a crucial case, and ones which may have negatively affected my career if I had not come across your site. That talents and kindness in playing with all the pieces was priceless. I am not sure what I would have done if I hadn't come across such a stuff like this. I'm able to at this point relish my future. Thank you very much for your skilled and sensible guide. I will not think twice to endorse your web sites to anybody who should receive direction about this issue.

ferragamo belt

2018-01-09 02:34:12

My spouse and i got now joyful Louis managed to do his investigation with the ideas he acquired out of your web page. It's not at all simplistic just to possibly be giving freely points that the rest have been trying to sell. And we also recognize we have the blog owner to thank for that. These explanations you've made, the straightforward site navigation, the friendships you will assist to create - it's everything extraordinary, and it is facilitating our son in addition to our family reason why the situation is enjoyable, which is seriously vital. Thanks for all!

yeezy

2018-01-10 12:09:31

I wanted to compose a simple note so as to express gratitude to you for the magnificent items you are sharing at this site. My long internet research has at the end of the day been paid with brilliant insight to talk about with my relatives. I 'd assume that most of us visitors are rather lucky to be in a fine network with many perfect professionals with very beneficial solutions. I feel truly happy to have encountered your web page and look forward to so many more pleasurable times reading here. Thanks once again for a lot of things.

adidas yeezy boost

2018-01-10 15:19:37

Thank you a lot for giving everyone such a nice chance to discover important secrets from here. It's always so cool plus stuffed with fun for me personally and my office fellow workers to search your website at the least three times in 7 days to read through the latest issues you have got. And definitely, I am also always satisfied with the spectacular principles you give. Certain 1 facts in this post are indeed the finest I have had.