作者 邓超

1

... ... @@ -6,4 +6,31 @@ include_once __DIR__."/../vendor/autoload.php";
//$ids = db()->all('select `id` from `'.\Model\emailSql::$table.'` limit 1000 offset 0');
//print_r($ids);
start_now_mail();
\ No newline at end of file
db()->insert('lists',[
'msgno' => 1,
'uid' => 1413523735,
'subject' => '',
'cc' => '',
'bcc' => '',
'from' => '15928184520@163.com',
'from_name' => 15928184520,
'to' => '281132704@qq.com',
'to_name' => '[{"email":"281132704@qq.com","name":"281132704"}]',
'date' => 1429682856,
'message_id' => '<201504220636.b57ac3935949@www.youni.com>',
'udate' => 1429682816,
'size' => 776,
'recent' => '',
'seen' => 1,
'draft' => '',
'flagged' => '',
'answered' => '',
'folder_id' => '',
'email_id' => 1,
'uuid' => '5da4967fd91dde5eb6ca68f31408d04f',
'is_file' => 0,
'created_at' => '2023-02-18 14:28:44'
]);
//start_now_mail();
\ No newline at end of file
... ...
... ... @@ -107,7 +107,7 @@ function start(){
}
// 每个协程 分配 10个邮箱任务
$cnum = ceil($email_total/40);
$cnum = ceil($email_total/(WORKER_NUM*10));
// 当前协程的数量
$nowCnum = count($cid);
// 说明 需要新的协程了
... ...
... ... @@ -3,7 +3,7 @@
error_reporting(E_ERROR | E_NOTICE);
// 开启4个进程
define('WORKER_NUM',4);
define('WORKER_NUM',2);
// 开启最大1000个协程
define('COROUTINE_MAX_NUM',1000);
// 是否继续运行
... ...
... ... @@ -2,6 +2,17 @@
/**
* 进程pid
* @return int
* @author:dc
* @time 2023/2/18 14:00
*/
function posix_pid(){
$pid = getmypid();
return $pid ? $pid : 0;
}
/**
* redis 驱动
* @return \Lib\RedisPool
* @author:dc
... ... @@ -9,7 +20,7 @@
*/
function redis():\Lib\RedisPool {
return \Lib\RedisPool::instance(co::getCid());
return \Lib\RedisPool::instance(posix_pid().co::getCid());
}
... ... @@ -22,7 +33,7 @@ function redis():\Lib\RedisPool {
*/
function db():\Lib\DbPool{
return \Lib\DbPool::instance(co::getCid());
return \Lib\DbPool::instance(posix_pid().co::getCid());
}
... ...
... ... @@ -95,6 +95,14 @@ class DbPool {
}
$sql = "update `{$table}` set ".dbUpdate($data). " where ".$where;
// 如果存储的值是数组,就json一次
foreach ($data as $k=>$datum){
if(is_array($data)){
$data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE);
}
}
$query = $this->query([$sql,$data]);
if($query){
return $query->rowCount();
... ... @@ -120,6 +128,13 @@ class DbPool {
$sql = "insert into `{$table}` set ".dbUpdate($data);
// 如果存储的值是数组,就json一次
foreach ($data as $k=>$datum){
if(is_array($data)){
$data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE);
}
}
$query = $this->query([$sql,$data]);
if($query){
... ...
... ... @@ -54,7 +54,7 @@ class Mail {
// 读取所有文件夹,未解密
$folders = $this->client->getFolder();
$db->transaction();
// $db->transaction();
foreach ($folders as $folder){
// 处理子父文件夹
$folder['id'] = explode('/',$folder['folder']);
... ... @@ -78,7 +78,7 @@ class Mail {
}
}
}
$db->commit();
// $db->commit();
}
... ... @@ -95,6 +95,7 @@ class Mail {
* @time 2023/2/18 9:54
*/
public function syncMail($email_id,$folder_id,$folder='INBOX',$db = null):bool {
// _echo('正在同步文件夹:'.$folder);
$db = $db ? $db : db();
// 选择文件夹
$status = $this->client->selectFolder($folder);
... ... @@ -196,7 +197,7 @@ class Mail {
$uuids = $db->all(listsSql::hasUuid(array_column($results,'uuid')));
$uuids = $uuids ? array_column($uuids,null,'uuid') : [];
$db->transaction();
// $db->transaction();
foreach ($results as $insert){
if(empty($uuids[$insert['uuid']])){
// 新增
... ... @@ -210,7 +211,7 @@ class Mail {
);
}
}
$db->commit();
// $db->commit();
// 更新数量
$db->update(
... ...