-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSendTask.php
More file actions
52 lines (45 loc) · 1.05 KB
/
SendTask.php
File metadata and controls
52 lines (45 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Created by PhpStorm.
* User: yzw
* Date: 2018/4/1 0001
* Time: 下午 21:53
*/
class SendTask
{
protected $workerPid;
protected $job;
public function __construct($job)
{
$this->job = $job;
$this->getWorkerPid();
}
public function getTaskContainer()
{
$redis = new Redis();
$redis->connect("127.0.0.1",6379);
return $redis;
}
public function pushTask()
{
//store job in the redis or other database
$this->storeTask();
var_dump($this->workerPid);
$this->wakeupWorker();
}
protected function storeTask()
{
//store job in the redis or other database like this
$redis = $this->getTaskContainer();
$redis->lpush("task_list",serialize($this->job));
//job must implements interface hanler
}
protected function wakeupWorker()
{
posix_kill($this->workerPid,SIGCONT);
}
protected function getWorkerPid()
{
$this->workerPid = (int)file_get_contents("worker_pid");
}
}