-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatching.php
51 lines (46 loc) · 1.25 KB
/
dispatching.php
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
<?php
/**
* dispatching.php
* Author: Ethan
* CreateTime: 2016/1/6 20:53
* Description: 线程调度器
*/
class dispatching
{
private static $pool = array();
public static function initPool()
{
$maxThreadNum = getConfig('maxThreadNum');
for($i = 0; $i < $maxThreadNum; $i ++)
{
self::$pool[$i] = new handleUser();
self::$pool[$i]->start(PTHREADS_INHERIT_ALL | PTHREADS_ALLOW_GLOBALS);
self::$pool[$i]->join();
//每隔50毫秒初始化一个线程
usleep(50);
}
}
}
class handleUser extends Thread
{
public function run()
{
$dbModel = loadClass('DBModel');
$userPageParam = array();
while(1)
{
//若为空则尝试自动获取
if(count($userPageParam) <= 0 || !isset($userPageParam['url']))
{
$userPageParam = $dbModel->getNext();
}
if(is_array($userPageParam) && count($userPageParam) > 0)
{
logMsg(SL_DEBUG,"Start to handle user : ".json_encode($userPageParam));
loadClass('userPage',$userPageParam);
$userPageParam = array();
}
usleep(500);
}
}
}