正在显示
6 个修改的文件
包含
63 行增加
和
9 行删除
@@ -6,4 +6,31 @@ include_once __DIR__."/../vendor/autoload.php"; | @@ -6,4 +6,31 @@ include_once __DIR__."/../vendor/autoload.php"; | ||
6 | //$ids = db()->all('select `id` from `'.\Model\emailSql::$table.'` limit 1000 offset 0'); | 6 | //$ids = db()->all('select `id` from `'.\Model\emailSql::$table.'` limit 1000 offset 0'); |
7 | //print_r($ids); | 7 | //print_r($ids); |
8 | 8 | ||
9 | -start_now_mail(); | ||
9 | +db()->insert('lists',[ | ||
10 | + | ||
11 | + 'msgno' => 1, | ||
12 | + 'uid' => 1413523735, | ||
13 | + 'subject' => '', | ||
14 | + 'cc' => '', | ||
15 | + 'bcc' => '', | ||
16 | + 'from' => '15928184520@163.com', | ||
17 | + 'from_name' => 15928184520, | ||
18 | + 'to' => '281132704@qq.com', | ||
19 | + 'to_name' => '[{"email":"281132704@qq.com","name":"281132704"}]', | ||
20 | + 'date' => 1429682856, | ||
21 | + 'message_id' => '<201504220636.b57ac3935949@www.youni.com>', | ||
22 | + 'udate' => 1429682816, | ||
23 | + 'size' => 776, | ||
24 | + 'recent' => '', | ||
25 | + 'seen' => 1, | ||
26 | + 'draft' => '', | ||
27 | + 'flagged' => '', | ||
28 | + 'answered' => '', | ||
29 | + 'folder_id' => '', | ||
30 | + 'email_id' => 1, | ||
31 | + 'uuid' => '5da4967fd91dde5eb6ca68f31408d04f', | ||
32 | + 'is_file' => 0, | ||
33 | + 'created_at' => '2023-02-18 14:28:44' | ||
34 | +]); | ||
35 | + | ||
36 | +//start_now_mail(); |
@@ -107,7 +107,7 @@ function start(){ | @@ -107,7 +107,7 @@ function start(){ | ||
107 | } | 107 | } |
108 | 108 | ||
109 | // 每个协程 分配 10个邮箱任务 | 109 | // 每个协程 分配 10个邮箱任务 |
110 | - $cnum = ceil($email_total/40); | 110 | + $cnum = ceil($email_total/(WORKER_NUM*10)); |
111 | // 当前协程的数量 | 111 | // 当前协程的数量 |
112 | $nowCnum = count($cid); | 112 | $nowCnum = count($cid); |
113 | // 说明 需要新的协程了 | 113 | // 说明 需要新的协程了 |
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | error_reporting(E_ERROR | E_NOTICE); | 3 | error_reporting(E_ERROR | E_NOTICE); |
4 | 4 | ||
5 | // 开启4个进程 | 5 | // 开启4个进程 |
6 | -define('WORKER_NUM',4); | 6 | +define('WORKER_NUM',2); |
7 | // 开启最大1000个协程 | 7 | // 开启最大1000个协程 |
8 | define('COROUTINE_MAX_NUM',1000); | 8 | define('COROUTINE_MAX_NUM',1000); |
9 | // 是否继续运行 | 9 | // 是否继续运行 |
@@ -2,6 +2,17 @@ | @@ -2,6 +2,17 @@ | ||
2 | 2 | ||
3 | 3 | ||
4 | /** | 4 | /** |
5 | + * 进程pid | ||
6 | + * @return int | ||
7 | + * @author:dc | ||
8 | + * @time 2023/2/18 14:00 | ||
9 | + */ | ||
10 | +function posix_pid(){ | ||
11 | + $pid = getmypid(); | ||
12 | + return $pid ? $pid : 0; | ||
13 | +} | ||
14 | + | ||
15 | +/** | ||
5 | * redis 驱动 | 16 | * redis 驱动 |
6 | * @return \Lib\RedisPool | 17 | * @return \Lib\RedisPool |
7 | * @author:dc | 18 | * @author:dc |
@@ -9,7 +20,7 @@ | @@ -9,7 +20,7 @@ | ||
9 | */ | 20 | */ |
10 | function redis():\Lib\RedisPool { | 21 | function redis():\Lib\RedisPool { |
11 | 22 | ||
12 | - return \Lib\RedisPool::instance(co::getCid()); | 23 | + return \Lib\RedisPool::instance(posix_pid().co::getCid()); |
13 | 24 | ||
14 | } | 25 | } |
15 | 26 | ||
@@ -22,7 +33,7 @@ function redis():\Lib\RedisPool { | @@ -22,7 +33,7 @@ function redis():\Lib\RedisPool { | ||
22 | */ | 33 | */ |
23 | function db():\Lib\DbPool{ | 34 | function db():\Lib\DbPool{ |
24 | 35 | ||
25 | - return \Lib\DbPool::instance(co::getCid()); | 36 | + return \Lib\DbPool::instance(posix_pid().co::getCid()); |
26 | } | 37 | } |
27 | 38 | ||
28 | 39 |
@@ -95,6 +95,14 @@ class DbPool { | @@ -95,6 +95,14 @@ class DbPool { | ||
95 | } | 95 | } |
96 | 96 | ||
97 | $sql = "update `{$table}` set ".dbUpdate($data). " where ".$where; | 97 | $sql = "update `{$table}` set ".dbUpdate($data). " where ".$where; |
98 | + | ||
99 | + // 如果存储的值是数组,就json一次 | ||
100 | + foreach ($data as $k=>$datum){ | ||
101 | + if(is_array($data)){ | ||
102 | + $data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE); | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
98 | $query = $this->query([$sql,$data]); | 106 | $query = $this->query([$sql,$data]); |
99 | if($query){ | 107 | if($query){ |
100 | return $query->rowCount(); | 108 | return $query->rowCount(); |
@@ -120,6 +128,13 @@ class DbPool { | @@ -120,6 +128,13 @@ class DbPool { | ||
120 | 128 | ||
121 | $sql = "insert into `{$table}` set ".dbUpdate($data); | 129 | $sql = "insert into `{$table}` set ".dbUpdate($data); |
122 | 130 | ||
131 | + // 如果存储的值是数组,就json一次 | ||
132 | + foreach ($data as $k=>$datum){ | ||
133 | + if(is_array($data)){ | ||
134 | + $data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE); | ||
135 | + } | ||
136 | + } | ||
137 | + | ||
123 | $query = $this->query([$sql,$data]); | 138 | $query = $this->query([$sql,$data]); |
124 | 139 | ||
125 | if($query){ | 140 | if($query){ |
@@ -54,7 +54,7 @@ class Mail { | @@ -54,7 +54,7 @@ class Mail { | ||
54 | // 读取所有文件夹,未解密 | 54 | // 读取所有文件夹,未解密 |
55 | $folders = $this->client->getFolder(); | 55 | $folders = $this->client->getFolder(); |
56 | 56 | ||
57 | - $db->transaction(); | 57 | +// $db->transaction(); |
58 | foreach ($folders as $folder){ | 58 | foreach ($folders as $folder){ |
59 | // 处理子父文件夹 | 59 | // 处理子父文件夹 |
60 | $folder['id'] = explode('/',$folder['folder']); | 60 | $folder['id'] = explode('/',$folder['folder']); |
@@ -78,7 +78,7 @@ class Mail { | @@ -78,7 +78,7 @@ class Mail { | ||
78 | } | 78 | } |
79 | } | 79 | } |
80 | } | 80 | } |
81 | - $db->commit(); | 81 | +// $db->commit(); |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
@@ -95,6 +95,7 @@ class Mail { | @@ -95,6 +95,7 @@ class Mail { | ||
95 | * @time 2023/2/18 9:54 | 95 | * @time 2023/2/18 9:54 |
96 | */ | 96 | */ |
97 | public function syncMail($email_id,$folder_id,$folder='INBOX',$db = null):bool { | 97 | public function syncMail($email_id,$folder_id,$folder='INBOX',$db = null):bool { |
98 | +// _echo('正在同步文件夹:'.$folder); | ||
98 | $db = $db ? $db : db(); | 99 | $db = $db ? $db : db(); |
99 | // 选择文件夹 | 100 | // 选择文件夹 |
100 | $status = $this->client->selectFolder($folder); | 101 | $status = $this->client->selectFolder($folder); |
@@ -196,7 +197,7 @@ class Mail { | @@ -196,7 +197,7 @@ class Mail { | ||
196 | $uuids = $db->all(listsSql::hasUuid(array_column($results,'uuid'))); | 197 | $uuids = $db->all(listsSql::hasUuid(array_column($results,'uuid'))); |
197 | $uuids = $uuids ? array_column($uuids,null,'uuid') : []; | 198 | $uuids = $uuids ? array_column($uuids,null,'uuid') : []; |
198 | 199 | ||
199 | - $db->transaction(); | 200 | +// $db->transaction(); |
200 | foreach ($results as $insert){ | 201 | foreach ($results as $insert){ |
201 | if(empty($uuids[$insert['uuid']])){ | 202 | if(empty($uuids[$insert['uuid']])){ |
202 | // 新增 | 203 | // 新增 |
@@ -210,7 +211,7 @@ class Mail { | @@ -210,7 +211,7 @@ class Mail { | ||
210 | ); | 211 | ); |
211 | } | 212 | } |
212 | } | 213 | } |
213 | - $db->commit(); | 214 | +// $db->commit(); |
214 | 215 | ||
215 | // 更新数量 | 216 | // 更新数量 |
216 | $db->update( | 217 | $db->update( |
-
请 注册 或 登录 后发表评论