...
|
...
|
@@ -27,7 +27,7 @@ function start(){ |
|
|
|
|
|
// 启动一个进程来管理定时
|
|
|
$pm->add(function (Process\Pool $pool, int $workerId)use (&$table){
|
|
|
_echo("进程({$workerId})启动成功");
|
|
|
_echo("定时进程({$workerId})启动成功");
|
|
|
// 每10分钟统计一次邮箱数量
|
|
|
\Swoole\Timer::tick(600000,function () use (&$table){
|
|
|
$table->set('etotal',['val'=> db()->count(\Model\emailSql::count())]);
|
...
|
...
|
@@ -60,6 +60,27 @@ function start(){ |
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
// 需要更新同步的邮件
|
|
|
\Swoole\Timer::tick(600000,function (){
|
|
|
|
|
|
$id = 0;
|
|
|
|
|
|
while (true){
|
|
|
$ids = db()->all('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1000 offset 0');
|
|
|
if(!$ids){
|
|
|
break;
|
|
|
}
|
|
|
foreach ($ids as $v){
|
|
|
$id = $v['id'];
|
|
|
redis()->rPush('sync_email_lists', $v['id']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 进行阻塞,否则定时器无法运行
|
|
|
while (true){
|
|
|
co::sleep(9999);
|
...
|
...
|
@@ -75,7 +96,7 @@ function start(){ |
|
|
|
|
|
// 启动业务进程
|
|
|
$pm->addBatch(WORKER_NUM,function (Process\Pool $pool, int $worker_id) use (&$table){
|
|
|
_echo("进程({$worker_id})启动成功");
|
|
|
_echo("业务进程({$worker_id})启动成功");
|
|
|
|
|
|
// 协程id集
|
|
|
$cid = [];
|
...
|
...
|
@@ -147,6 +168,7 @@ function start(){ |
|
|
},true);
|
|
|
|
|
|
|
|
|
// 启动管理器
|
|
|
$pm->start();
|
|
|
|
|
|
}
|
...
|
...
|
@@ -195,12 +217,50 @@ function create_coroutine(array &$cid,int &$isRunMaxCNum,$worker_id){ |
|
|
|
|
|
|
|
|
/**
|
|
|
* 开始同步
|
|
|
* 开始同步, 这里是主要的业务代码
|
|
|
* @author:dc
|
|
|
* @time 2023/2/13 9:42
|
|
|
*/
|
|
|
function sync(){
|
|
|
co::sleep(1);
|
|
|
// 需要同步的id
|
|
|
$id = redis()->lPop('sync_email_lists');
|
|
|
if(!$id){
|
|
|
co::sleep(1);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
$email = db()->first(\Model\emailSql::first($id));
|
|
|
if(!$email){
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
if($email['pwd_error']){
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
$mailServer = new Lib\Mail\Mail();
|
|
|
|
|
|
try {
|
|
|
// 登录服务器
|
|
|
$mailServer->login($email['email'],base64_decode($email['password']),$email['imap']);
|
|
|
}catch (Throwable $e){
|
|
|
if($e->getCode() == 403){
|
|
|
// 登录失败了 ,
|
|
|
db()->update(\Model\emailSql::$table,['pwd_error'=>1],dbWhere(['id'=>$id]));
|
|
|
}
|
|
|
|
|
|
return 2;
|
|
|
}
|
|
|
|
|
|
$mailServer->client->setId($id);
|
|
|
// 同步文件夹
|
|
|
$mailServer->syncFolder($email['email'],db());
|
|
|
|
|
|
|
|
|
|
|
|
$email = null;
|
|
|
$mailServer = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|