sync_my.php
1.1 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
<?php
//error_reporting();
include_once __DIR__."/../vendor/autoload.php";
swoole_set_process_name('php-email-sync-list-my');
$pm = new \Swoole\Process\Manager();
$pm->addBatch(30,function ($work_id){
$number = 0;
while (1){
if($number>500){
break;
}
$id = redis()->lPop('sync_email_lists_my');
if($id && is_numeric($id)){
// 占用当前的id,占用2小时
if(redis()->add('just_sync_'.$id,time(),600)){
$number++;
try{
// 开始同步
$email = db()->cache(3600)->first(\Model\emailSql::first($id));
if($email){
(new \Service\SyncMail($email))->sync();
}
}catch (Throwable $e){
logs('sync : '.$e->getMessage());
}
// 30秒后 消除占用
redis()->expire('just_sync_'.$id,120);
}
}else{
sleep(1);
}
}
_echo('子进程即将推出');
});
$pm->start();