切换导航条
此项目
正在载入...
登录
周海龙
/
mail-serve
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
邓超
23 days ago
提交
256e76ed0fb3861b1d08674fb440264892afa644
1 个父辈
a8b197ac
sync
显示空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
49 行增加
和
60 行删除
cmd/sync_my.php
lib/RedisPool.php
cmd/sync_my.php
查看文件 @
256e76e
<?php
// 进程管理器
$pm
=
new
\Swoole\Process\Manager
();
// 启动业务进程
$pm
->
addBatch
(
5
,
function
(
\Swoole\Process\Pool
$pool
,
int
$worker_id
){
//error_reporting();
include_once
__DIR__
.
"/../vendor/autoload.php"
;
class
SyncEmailMy
{
static
$maxGo
=
0
;
public
static
function
sync
(){
_echo
(
'子进程重新启动了==>'
.
$worker_id
);
\Lib\DbPool
::
$clientNumber
=
52
;
\Lib\RedisPool
::
$clientNumber
=
52
;
while
(
1
){
// if(self::$maxGo >= 50){
// co::sleep(1);
// continue;
// }
if
(
\Lib\SwGo
::
$runNumber
>=
50
){
co
::
sleep
(
1
);
continue
;
}
$id
=
redis
()
->
lPop
(
'sync_email_lists_my'
);
// _echo('读取到'.$id);
...
...
@@ -21,20 +25,8 @@ class SyncEmailMy{
// 占用当前的id,占用2小时
if
(
redis
()
->
add
(
'just_sync_'
.
$id
,
time
(),
600
)){
self
::
go
(
$id
);
}
// co::sleep(0.2);
}
else
{
sleep
(
1
);
}
}
}
\Lib\SwGo
::
start
(
function
(
$id
){
public
static
function
go
(
$id
){
// go(function ($id){
// self::$maxGo++;
try
{
// 开始同步
(
new
\Service\SyncMail
(
$id
))
->
isUidAfter
(
2
)
->
sync
();
...
...
@@ -42,36 +34,18 @@ class SyncEmailMy{
_echo
(
$e
->
getMessage
());
}
// co::defer(function () use ($id){
// self::$maxGo--;
// 30秒后 消除占用
redis
()
->
expire
(
'just_sync_'
.
$id
,
30
);
},
$id
);
\Lib\Log
::
getInstance
()
->
write
();
// db()->close();
// });
// },$id);
}
co
::
sleep
(
0.2
);
}
else
{
co
::
sleep
(
1
);
}
}
// 进程管理器
$pm
=
new
\Swoole\Process\Manager
();
// 启动业务进程
$pm
->
addBatch
(
100
,
function
(
\Swoole\Process\Pool
$pool
,
int
$worker_id
){
//error_reporting();
include_once
__DIR__
.
"/../vendor/autoload.php"
;
_echo
(
'子进程重新启动了==>'
.
$worker_id
);
\Lib\DbPool
::
$clientNumber
=
60
;
SyncEmailMy
::
sync
();
}
},
fals
e
);
},
tru
e
);
$pm
->
start
();
...
...
lib/RedisPool.php
查看文件 @
256e76e
...
...
@@ -19,6 +19,17 @@ class RedisPool {
*/
static
$pool
=
null
;
/**
* 获取到的连接
* @var array
*/
public
static
$clientAll
=
[];
/**
* 连接的数量
* @var int
*/
public
static
$clientNumber
=
1024
;
/**
* RedisPool constructor.
...
...
@@ -33,35 +44,39 @@ class RedisPool {
->
withAuth
(
REDIS_PASSWORD
)
->
withDbIndex
(
REDIS_DB
)
->
withTimeout
(
60
)
,
1024
,
self
::
$clientNumber
);
}
// 获取一个连接,放入当前实例
$this
->
client
=
static
::
$pool
->
get
();
}
public
function
getClient
()
{
$id
=
\co
::
getCid
();
if
(
empty
(
static
::
$clientAll
[
$id
])){
static
::
$clientAll
[
$id
]
=
self
::
$pool
->
get
();
}
return
static
::
$clientAll
[
$id
];
}
public
function
__destruct
()
{
$this
->
close
();
//
$this->close();
}
/**
* 关闭
* 关闭
链接
* @author:dc
* @time 202
3/3/16 13:42
* @time 202
4/5/30 10:30
*/
public
function
close
(){
self
::
$pool
->
put
(
$this
->
client
);
$this
->
client
=
null
;
$id
=
\co
::
getCid
();
if
(
isset
(
static
::
$clientAll
[
$id
])){
self
::
$pool
->
put
(
static
::
$clientAll
[
$id
]);
}
unset
(
static
::
$clientAll
[
$id
]);
}
...
...
请
注册
或
登录
后发表评论