作者 邓超

优化同步

... ... @@ -5,30 +5,6 @@ include_once __DIR__."/../vendor/autoload.php";
swoole_set_process_name('php-email-sync-list-my');
function stop(){
if(redis()->add('sync_my_pid_lock',getmypid(),10)){
$keys = redis()->keys('sync_my_pid:*');
foreach ($keys as $key){
list($k,$pid) = explode(':',$key);
if(posix_kill($pid,0)){
$t = redis()->get($key);
if(time()-$t > 60){
_echo('向'.$pid.'发送终止信号');
if(posix_kill($pid,SIGTERM)){
redis()->delete($key);
}
}
}else{
redis()->delete($key);
}
}
redis()->delete('sync_my_pid_lock');
}
}
\Co\run(function (){
$goNum = 0;
while (1){
... ... @@ -39,10 +15,6 @@ function stop(){
}
$id = redis()->lPop('sync_email_lists_my');
redis()->set('sync_my_pid:'.getmypid(),time(),86400);
stop();
// _echo('读取到'.$id);
if($id && is_numeric($id)){
// 占用当前的id,占用2小时
... ... @@ -52,7 +24,7 @@ function stop(){
$goNum++;
try{
// 开始同步
(new \Service\SyncMail($id))->sync();
(new \Service\SyncMail($id))->isUidAfter(2)->sync();
}catch (Throwable $e){
_echo($e->getMessage());
}
... ...