sync_my.php
1.4 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
// 进程管理器
$pm = new \Swoole\Process\Manager();
// 启动业务进程
$pm->addBatch(3,function (\Swoole\Process\Pool $pool, int $worker_id){
    if($worker_id===0){
        $i=300;
        while($i>0){
            $i--;
            co::sleep(5);
        }
        $pool->shutdown();
        return 0;
    }
    //error_reporting();
    include_once __DIR__."/../vendor/autoload.php";
    _echo('子进程重新启动了==>'.$worker_id);
    \Lib\DbPool::$clientNumber = 52;
    \Lib\RedisPool::$clientNumber = 52;
    while (1){
        if(\Lib\SwGo::$runNumber >= 50){
            co::sleep(1);
            continue;
        }
        $id = redis()->lPop('sync_email_lists_my');
        // _echo('读取到'.$id);
        if($id && is_numeric($id)){
            // 占用当前的id,占用2小时
            if(redis()->add('just_sync_'.$id,time(),300)){
                \Lib\SwGo::start(function ($id){
                    try{
                        // 开始同步
                        (new \Service\SyncMail($id))->isUidAfter(2)->sync();
                    }catch (Throwable $e){
                        _echo($e->getMessage());
                    }
                    redis()->expire('just_sync_'.$id,30);
                },$id);
            }
                co::sleep(0.2);
        }else{
            co::sleep(1);
        }
    }
},true);
$pm->start();
