Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
9a4106ae
Commit
9a4106ae
authored
Jan 17, 2019
by
liuyuzhen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ccw' of git.shenbd.com:qm-develop/shenbd into lyz_index
parents
b7949f0b
6431037f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
508 additions
and
148 deletions
+508
-148
a.php
a.php
+3
-1
OrderService.php
application/models/Business/Order/OrderService.php
+1
-1
application.ini
conf/application.ini
+5
-5
bridge.php
scripts/crontab/push/bridge.php
+1
-1
bridgeBase.php
scripts/crontab/push/bridgeBase.php
+61
-0
bridgeStart.php
scripts/crontab/push/bridgeStart.php
+54
-139
bridgeStart_bak.php
scripts/crontab/push/bridgeStart_bak.php
+151
-0
runRedisBase.php
scripts/crontab/push/runRedisBase.php
+47
-0
runRedisCanReload.php
scripts/crontab/push/runRedisCanReload.php
+183
-0
runRedisPush.php
scripts/crontab/push/runRedisPush.php
+2
-1
No files found.
a.php
View file @
9a4106ae
<?php
phpinfo
();
exit
;
//phpinfo();exit;
echo
'is nothing'
;
exit
;
header
(
"Content-type: text/html; charset=utf-8"
);
//利用PHP目录和文件函数遍历用户给出目录的所有的文件和文件夹,修改文件名称
function
fRename
(
$dirname
)
...
...
application/models/Business/Order/OrderService.php
View file @
9a4106ae
...
...
@@ -578,7 +578,7 @@ class OrderServiceModel extends \Business\AbstractModel
$storeDao
=
\DAO\StoreModel
::
getInstance
();
//判断订单目前状态是否允许取消
$isAllowCancel
=
$orderDao
->
isAllowCancel
(
$order
);
$isAllowCancel
=
true
;
//
$isAllowCancel = true;
if
(
$isAllowCancel
)
{
$orderDao
->
db
->
doTransaction
();
$res
=
$orderDao
->
updateStatusByOrderId
(
$orderId
,
ApiConst
::
orderStateCancel
,
false
,
ApiConst
::
cancelOrderBySelf
);
...
...
conf/application.ini
View file @
9a4106ae
...
...
@@ -316,10 +316,10 @@ resources.database.mongo.params.driver_options.1002 = "SET NAMES utf8"
password.key
=
'~!@#$`1234qwertasdfgzxcvb'
;
redis.database.params.host
=
"192.168.1.
201
"
redis.database.params.host
=
"192.168.1.
180
"
redis.database.params.port
=
"6379"
redis.database.params.prefix
=
"qm_"
redis.database.params.password
=
""
redis.database.params.password
=
"
23456ertyu
"
out.config
=
"/data/config"
;
;锁文件
...
...
@@ -328,13 +328,13 @@ out.locks="/data/locks";
;redis.database.params.password = "test"
;推送配置
push.clientHost
=
"ws://192.168.1.
201
:9502"
push.host
=
"192.168.1.
201
"
push.clientHost
=
"ws://192.168.1.
180
:9502"
push.host
=
"192.168.1.
180
"
push.port
=
"9503"
push.open
=
1
push.user.service.id
=
293
push.user.service.type
=
7
elastic.master.host
=
"192.168.1.
201
"
elastic.master.host
=
"192.168.1.
180
"
elastic.master.port
=
"9200"
elastic.master.scheme
=
"http"
;
;resources.database.params.hostname = "127.0.0.1"
...
...
scripts/crontab/push/bridge.php
View file @
9a4106ae
...
...
@@ -41,7 +41,7 @@ $http->on('request', function ($request, $response) {
throw
new
Exception
(
$ex
->
getMessage
(),
$ex
->
getCode
());
}
});
$http
->
start
();
scripts/crontab/push/bridgeBase.php
0 → 100644
View file @
9a4106ae
<?php
if
(
!
empty
(
$request
->
post
)){
try
{
$respData
=
$request
->
post
;
// echo json_encode($respData);
if
(
isset
(
$respData
[
'type'
])
&&
$respData
[
'type'
]
==
1
){
$info
=
$respData
[
'content'
];
$memberDao
=
$info
[
'className'
]
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
echo
json_encode
(
$info
);
if
(
empty
(
$info
[
'params'
])){
$res
=
call_user_func_array
(
array
(
$memberDao
,
$info
[
'method'
]),
array
());
}
else
{
$res
=
call_user_func_array
(
array
(
$memberDao
,
$info
[
'method'
]),
$info
[
'params'
]);
}
$res
=
(
isset
(
$res
)
&&!
empty
(
$res
))
?
$res
:
false
;
unset
(
$memberDao
);
\Mysql\LinkMySQLModel
::
unsetDbConecet
();
if
(
$res
!==
false
){
echo
'success'
.
PHP_EOL
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
1
,
'message'
=>
'执行成功'
,
'data'
=>
$res
)));
}
else
{
echo
'fail1'
.
PHP_EOL
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
else
{
echo
'fail2'
.
PHP_EOL
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
catch
(
Exception
$ex
){
throw
new
Exception
(
$ex
->
getMessage
(),
$ex
->
getCode
());
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
else
{
// 通过链接参数热重载 worker 进程观察触发事件
if
(
!
empty
(
$request
->
get
)){
$act
=
$request
->
get
[
'act'
]
?
$request
->
get
[
'act'
]
:
''
;
if
(
$act
==
'reload'
)
{
echo
' ... Swoole Reloading ! ... '
.
PHP_EOL
.
PHP_EOL
;
// 触发 reload 之后, 貌似后面的代码也还是会执行的
$http
->
reload
();
echo
' ... Under Reload ! ... '
.
PHP_EOL
.
PHP_EOL
;
// 看看 reload 时是否会执行后续的代码
$response
->
end
(
json_encode
(
array
(
'status'
=>
1
,
'message'
=>
'重启成功'
)));
}
elseif
(
$act
==
'stop'
)
{
// 直接立即终止当前 worker 进程, 和 reload 的效果比较相似, 新的 worker 进程的 ID 和原来的一样
// 所以程序内部应该尽量避免使用 exit 而应该抛出异常在外部 catch
echo
' ... Swoole Exit ! ... '
.
PHP_EOL
.
PHP_EOL
;
exit
;
}
elseif
(
$act
==
'shutdown'
)
{
// 直接立即终止当前 worker 进程, 和 reload 的效果比较相似, 新的 worker 进程的 ID 和原来的
// 所以程序内部应该尽量避免使用 exit 而应该抛出异常在外部 catch
echo
' ... Swoole Shutdown ! ... '
.
PHP_EOL
.
PHP_EOL
;
$http
->
shutdown
();
echo
' ... After Swoole Shutdown ! ... '
.
PHP_EOL
.
PHP_EOL
;
}
}
else
{
$response
->
end
(
json_encode
(
array
(
'status'
=>
1
,
'message'
=>
'请求成功'
)));
}
}
scripts/crontab/push/bridgeStart.php
View file @
9a4106ae
<?php
/**
*
* 脚本
*
* @author ccw <31435391@qq.com>
*/
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
require
APPLICATION_PATH
.
'/scripts/crontab/baseCli.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
class
bridgeStart
{
/* config */
const
LISTEN
=
"tcp://192.168.2.15:5555"
;
const
MAXCONN
=
100
;
const
pidfile
=
__CLASS__
;
const
uid
=
81
;
const
gid
=
81
;
/**/
protected
$pool
=
NULL
;
protected
$zmq
=
NULL
;
public
function
__construct
()
{
$this
->
pidfile
=
'/var/run/'
.
self
::
pidfile
.
'.pid'
;
}
$http
=
new
swoole_http_server
(
"0.0.0.0"
,
9501
);
private
function
daemon
()
{
if
(
file_exists
(
$this
->
pidfile
))
{
echo
"The file
$this->pidfile
exists.
\n
"
;
exit
();
}
/**
* 测试在 $server 外部注册全局自定义属性, 看看会不会被覆盖
*/
$pid
=
pcntl_fork
();
if
(
$pid
==
-
1
)
{
die
(
'could not fork'
);
}
else
if
(
$pid
)
{
// we are the parent
//pcntl_wait($status); //Protect against Zombie children
exit
(
$pid
);
}
else
{
// we are the child
file_put_contents
(
$this
->
pidfile
,
getmypid
());
posix_setuid
(
self
::
uid
);
posix_setgid
(
self
::
gid
);
return
(
getmypid
());
}
}
public
function
callback
(
$instance
,
$channelName
,
$message
){
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
$orderService
->
testPush
(
$message
);
}
protected
function
status
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
printf
(
"%s already running, pid = %s
\n
"
,
$this
->
argv
[
0
],
$pid
);
}
else
{
printf
(
"%s haven't running
\n
"
,
$this
->
argv
[
0
]);
}
}
private
function
start
()
{
$pid
=
$this
->
daemon
();
$conf
=
\Yaf\Registry
::
get
(
'config'
)
->
get
(
'redis.database.params'
);
$http
=
new
swoole_http_server
(
"0.0.0.0"
,
9501
);
$http
->
on
(
'request'
,
function
(
$request
,
$response
)
{
try
{
$respData
=
$request
->
post
;
// echo json_encode($respData);
/**
* 测试在 $server 外部注册全局自定义属性, 看看会不会被覆盖
*/
if
(
isset
(
$respData
[
'type'
])
&&
$respData
[
'type'
]
==
1
){
$info
=
$respData
[
'content'
];
$memberDao
=
$info
[
'className'
]
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
echo
json_encode
(
$info
);
if
(
empty
(
$info
[
'params'
])){
$res
=
call_user_func_array
(
array
(
$memberDao
,
$info
[
'method'
]),
array
());
}
else
{
$res
=
call_user_func_array
(
array
(
$memberDao
,
$info
[
'method'
]),
$info
[
'params'
]);
}
$res
=
(
isset
(
$res
)
&&!
empty
(
$res
))
?
$res
:
false
;
unset
(
$memberDao
);
\Mysql\LinkMySQLModel
::
unsetDbConecet
();
if
(
$res
!==
false
){
echo
'success'
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
1
,
'message'
=>
'执行成功'
,
'data'
=>
$res
)));
}
else
{
echo
'fail1'
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
else
{
echo
'fail2'
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
catch
(
Exception
$ex
){
throw
new
Exception
(
$ex
->
getMessage
(),
$ex
->
getCode
());
}
});
$http
->
start
();
$http
->
myWorkerVar
=
'global'
;
}
private
function
reload
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
//posix_kill(posix_getpid(), SIGHUP);
posix_kill
(
$pid
,
SIGHUP
);
}
}
protected
function
restart
(){
$this
->
stop
();
sleep
(
1
);
$this
->
start
();
}
$http
->
set
(
array
(
'worker_num'
=>
5
,
'daemonize'
=>
false
,
));
private
function
stop
()
{
// 服务器启动时执行一次
$http
->
on
(
'Start'
,
function
(
swoole_http_server
$server
)
{
echo
''
;
});
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
posix_kill
(
$pid
,
9
);
unlink
(
$this
->
pidfile
);
}
}
// 服务器启动时执行一次
$http
->
on
(
'ManagerStart'
,
function
(
swoole_http_server
$server
)
{
echo
'ManagerStart: '
.
PHP_EOL
.
PHP_EOL
;
});
private
function
help
(
$proc
)
{
printf
(
"%s start | stop | help | restart | reload
\n
"
,
$proc
);
}
private
$argv
;
public
function
main
(
$argv
)
{
$this
->
argv
=
$argv
;
if
(
count
(
$argv
)
<
2
)
{
printf
(
"please input help parameter
\n
"
);
exit
();
}
if
(
$argv
[
1
]
===
'stop'
)
{
// 每个 Worker 进程启动或重启时都会执行
$http
->
on
(
'WorkerStart'
,
function
(
swoole_http_server
$server
,
$workerId
)
{
// 通过重新加载外部文件来重载代码和释放之前占用的内存
//include_once __DIR__ . DIRECTORY_SEPARATOR .'workerstart.php';
// 下面这些直接写在当前文件中的代码即便重载也不会变化
echo
'WorkerStart: '
.
PHP_EOL
.
PHP_EOL
;
echo
' Worker ID: '
.
$workerId
.
PHP_EOL
.
PHP_EOL
;
// 启动服务器后, 去掉下面这行注释, 然后 reload , 该语句也不会执行的
//echo ' reloaded ! ' . PHP_EOL . PHP_EOL;
// 应该把这里的回调事件代码写在另一个文件中来 include 而不是直接写在这里
// 注意即便是 include_once , reload 也会重新加载的, 但在你的逻辑控制中是有效的
});
// 每次连接时(相当于每个浏览器第一次打开页面时)执行一次, reload 时连接不会断开, 也就不会再次触发该事件
$http
->
on
(
'Connect'
,
function
(
swoole_http_server
$server
,
$fd
,
$reactorThreadId
)
{
echo
'Worker ID: '
.
$server
->
worker_id
.
';'
.
'fd: '
.
$fd
.
' , fromId: '
.
$reactorThreadId
.
PHP_EOL
;
});
// 浏览器连接服务器后, 页面上的每个请求均会执行一次,
// 每次打开链接页面默认都是接收两个请求, 一个是正常的数据请求, 一个 favicon.ico 的请求
$http
->
on
(
'request'
,
function
(
$request
,
$response
)
use
(
$http
)
{
require_once
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/push/bridgeBase.php'
;
});
$http
->
start
();
$this
->
stop
();
}
else
if
(
$argv
[
1
]
===
'start'
)
{
$this
->
start
();
}
else
if
(
$argv
[
1
]
===
'restart'
){
$this
->
restart
();
}
else
if
(
$argv
[
1
]
===
'status'
){
$this
->
status
();
}
else
if
(
$argv
[
1
]
===
'reload'
){
$this
->
reload
();
}
else
{
$this
->
help
(
$argv
[
0
]);
}
}
}
$cgse
=
new
bridgeStart
();
$cgse
->
main
(
$argv
);
\ No newline at end of file
scripts/crontab/push/bridgeStart_bak.php
0 → 100644
View file @
9a4106ae
<?php
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
require
APPLICATION_PATH
.
'/scripts/crontab/baseCli.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
class
bridgeStart
{
/* config */
const
LISTEN
=
"tcp://192.168.2.15:5555"
;
const
MAXCONN
=
100
;
const
pidfile
=
__CLASS__
;
const
uid
=
81
;
const
gid
=
81
;
/**/
protected
$pool
=
NULL
;
protected
$zmq
=
NULL
;
public
function
__construct
()
{
$this
->
pidfile
=
'/var/run/'
.
self
::
pidfile
.
'.pid'
;
}
private
function
daemon
()
{
if
(
file_exists
(
$this
->
pidfile
))
{
echo
"The file
$this->pidfile
exists.
\n
"
;
exit
();
}
$pid
=
pcntl_fork
();
if
(
$pid
==
-
1
)
{
die
(
'could not fork'
);
}
else
if
(
$pid
)
{
// we are the parent
//pcntl_wait($status); //Protect against Zombie children
exit
(
$pid
);
}
else
{
// we are the child
file_put_contents
(
$this
->
pidfile
,
getmypid
());
posix_setuid
(
self
::
uid
);
posix_setgid
(
self
::
gid
);
return
(
getmypid
());
}
}
public
function
callback
(
$instance
,
$channelName
,
$message
){
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
$orderService
->
testPush
(
$message
);
}
protected
function
status
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
printf
(
"%s already running, pid = %s
\n
"
,
$this
->
argv
[
0
],
$pid
);
}
else
{
printf
(
"%s haven't running
\n
"
,
$this
->
argv
[
0
]);
}
}
private
function
start
()
{
$pid
=
$this
->
daemon
();
$conf
=
\Yaf\Registry
::
get
(
'config'
)
->
get
(
'redis.database.params'
);
$http
=
new
swoole_http_server
(
"0.0.0.0"
,
9501
);
$http
->
on
(
'request'
,
function
(
$request
,
$response
)
{
try
{
$respData
=
$request
->
post
;
// echo json_encode($respData);
if
(
isset
(
$respData
[
'type'
])
&&
$respData
[
'type'
]
==
1
){
$info
=
$respData
[
'content'
];
$memberDao
=
$info
[
'className'
]
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
echo
json_encode
(
$info
);
if
(
empty
(
$info
[
'params'
])){
$res
=
call_user_func_array
(
array
(
$memberDao
,
$info
[
'method'
]),
array
());
}
else
{
$res
=
call_user_func_array
(
array
(
$memberDao
,
$info
[
'method'
]),
$info
[
'params'
]);
}
$res
=
(
isset
(
$res
)
&&!
empty
(
$res
))
?
$res
:
false
;
unset
(
$memberDao
);
\Mysql\LinkMySQLModel
::
unsetDbConecet
();
if
(
$res
!==
false
){
echo
'success'
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
1
,
'message'
=>
'执行成功'
,
'data'
=>
$res
)));
}
else
{
echo
'fail1'
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
else
{
echo
'fail2'
;
$response
->
end
(
json_encode
(
array
(
'status'
=>
0
,
'message'
=>
'执行失败'
)));
}
}
catch
(
Exception
$ex
){
throw
new
Exception
(
$ex
->
getMessage
(),
$ex
->
getCode
());
}
});
$http
->
start
();
}
private
function
reload
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
//posix_kill(posix_getpid(), SIGHUP);
posix_kill
(
$pid
,
SIGHUP
);
}
}
protected
function
restart
(){
$this
->
stop
();
sleep
(
1
);
$this
->
start
();
}
private
function
stop
()
{
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
posix_kill
(
$pid
,
9
);
unlink
(
$this
->
pidfile
);
}
}
private
function
help
(
$proc
)
{
printf
(
"%s start | stop | help | restart | reload
\n
"
,
$proc
);
}
private
$argv
;
public
function
main
(
$argv
)
{
$this
->
argv
=
$argv
;
if
(
count
(
$argv
)
<
2
)
{
printf
(
"please input help parameter
\n
"
);
exit
();
}
if
(
$argv
[
1
]
===
'stop'
)
{
$this
->
stop
();
}
else
if
(
$argv
[
1
]
===
'start'
)
{
$this
->
start
();
}
else
if
(
$argv
[
1
]
===
'restart'
){
$this
->
restart
();
}
else
if
(
$argv
[
1
]
===
'status'
){
$this
->
status
();
}
else
if
(
$argv
[
1
]
===
'reload'
){
$this
->
reload
();
}
else
{
$this
->
help
(
$argv
[
0
]);
}
}
}
$cgse
=
new
bridgeStart
();
$cgse
->
main
(
$argv
);
\ No newline at end of file
scripts/crontab/push/runRedisBase.php
0 → 100644
View file @
9a4106ae
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/17 0017
* Time: 下午 2:29
*/
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
$conf
=
\Yaf\Registry
::
get
(
'config'
)
->
get
(
'redis.database.params'
);
$redisPublishName
=
\Yaf\Registry
::
get
(
'config'
)
->
get
(
'redis.redisPublishName'
);
function
callback
(
$instance
,
$channelName
,
$message
){
try
{
$message
=
json_decode
(
$message
,
true
);
$callInstance
=
$message
[
'className'
]
::
getInstance
(
\Our\DbNameConst
::
masterDBConnectName
);
echo
json_encode
(
$message
)
.
"
\r\n
"
;
if
(
empty
(
$message
[
'params'
])){
$res
=
call_user_func_array
(
array
(
$callInstance
,
$message
[
'method'
]),
array
());
}
else
{
$res
=
call_user_func_array
(
array
(
$callInstance
,
$message
[
'method'
]),
$message
[
'params'
]);
}
$res
=
(
isset
(
$res
)
&&!
empty
(
$res
))
?
$res
:
false
;
if
(
$res
!==
false
){
echo
'success'
.
"
\r\n
"
;
}
else
{
echo
'fail1'
.
"
\r\n
"
;
}
unset
(
$callInstance
);
\Mysql\LinkMySQLModel
::
unsetDbConecet
();
}
catch
(
Exception
$ex
){
echo
$ex
->
getMessage
();
}
$instance
->
unsubscribe
(
array
(
$channelName
));
$instance
->
close
();
}
$redis
=
new
Redis
();
$redis
->
connect
(
$conf
[
'host'
],
$conf
[
'port'
]);
if
(
!
empty
(
$conf
[
'password'
])){
$redis
->
auth
(
$conf
[
'password'
]);
}
//ini_set('default_socket_timeout', -1);(所有长连接不超时)
$redis
->
setOption
(
Redis
::
OPT_READ_TIMEOUT
,
-
1
);
$result
=
$redis
->
subscribe
(
array
(
$redisPublishName
),
'callback'
);
$redis
->
close
();
echo
'abcdef'
.
"
\r\n
"
;
\ No newline at end of file
scripts/crontab/push/runRedisCanReload.php
0 → 100644
View file @
9a4106ae
<?php
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
class
Logger
{
public
function
__construct
(
/*Logging $logger*/
)
{
}
public
function
logger
(
$type
,
$message
)
{
$log
=
sprintf
(
"%s
\t
%s
\t
%s
\n
"
,
date
(
'Y-m-d H:i:s'
),
$type
,
$message
);
file_put_contents
(
sprintf
(
__DIR__
.
"/../log/sender.%s.log"
,
date
(
'Y-m-d'
)),
$log
,
FILE_APPEND
);
}
}
final
class
Signal
{
public
static
$signo
=
0
;
protected
static
$ini
=
null
;
public
static
function
set
(
$signo
){
self
::
$signo
=
$signo
;
}
public
static
function
get
(){
return
(
self
::
$signo
);
}
public
static
function
reset
(){
self
::
$signo
=
0
;
}
}
class
Test
extends
Logger
{
//public static $signal = null;
public
function
__construct
()
{
//self::$signal == null;
}
public
function
run
()
{
require
APPLICATION_PATH
.
'/scripts/crontab/push/runRedisBase.php'
;
pcntl_signal_dispatch
();
printf
(
".123"
);
sleep
(
1
);
if
(
Signal
::
get
()
==
SIGHUP
)
{
Signal
::
reset
();
// break;
}
// while (true) {
// pcntl_signal_dispatch();
// printf(".123");
// sleep(1);
// if (Signal::get() == SIGHUP) {
// Signal::reset();
// break;
// }
//
// }
printf
(
"
\n
"
);
}
}
class
Daemon
extends
Logger
{
/* config */
const
LISTEN
=
"tcp://192.168.2.15:5555"
;
const
pidfile
=
__CLASS__
;
const
uid
=
80
;
const
gid
=
80
;
const
sleep
=
5
;
protected
$pool
=
NULL
;
protected
$config
=
array
();
public
function
__construct
(
$uid
,
$gid
,
$class
)
{
$this
->
pidfile
=
'/var/run/'
.
basename
(
get_class
(
$class
),
'.php'
)
.
'.pid'
;
//$this->config = parse_ini_file('sender.ini', true); //include_once(__DIR__."/config.php");
$this
->
uid
=
$uid
;
$this
->
gid
=
$gid
;
$this
->
class
=
$class
;
$this
->
classname
=
get_class
(
$class
);
$this
->
signal
();
}
public
function
signal
(){
pcntl_signal
(
SIGHUP
,
function
(
$signo
)
/*use ()*/
{
//echo "\n This signal is called. [$signo] \n";
printf
(
"The process has been reload.
\n
"
);
Signal
::
set
(
$signo
);
$this
->
run
();
});
}
private
function
daemon
(){
if
(
file_exists
(
$this
->
pidfile
))
{
echo
"The file
$this->pidfile
exists.
\n
"
;
exit
();
}
$pid
=
pcntl_fork
();
if
(
$pid
==
-
1
)
{
die
(
'could not fork'
);
}
else
if
(
$pid
)
{
// we are the parent
//pcntl_wait($status); //Protect against Zombie children
exit
(
$pid
);
}
else
{
file_put_contents
(
$this
->
pidfile
,
getmypid
());
posix_setuid
(
self
::
uid
);
posix_setgid
(
self
::
gid
);
return
(
getmypid
());
}
}
private
function
run
(){
while
(
true
){
printf
(
"The process begin.
\n
"
);
$this
->
class
->
run
();
printf
(
"The process end.
\n
"
);
}
}
private
function
foreground
(){
$this
->
run
();
}
private
function
start
(){
$pid
=
$this
->
daemon
();
for
(;;){
$this
->
run
();
sleep
(
self
::
sleep
);
}
}
private
function
stop
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
posix_kill
(
$pid
,
9
);
unlink
(
$this
->
pidfile
);
}
}
private
function
reload
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
//posix_kill(posix_getpid(), SIGHUP);
posix_kill
(
$pid
,
SIGHUP
);
}
}
private
function
status
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
system
(
sprintf
(
"ps ax | grep %s | grep -v grep"
,
$pid
));
}
}
private
function
help
(
$proc
){
printf
(
"%s start | stop | restart | status | foreground | help
\n
"
,
$proc
);
}
public
function
main
(
$argv
){
if
(
count
(
$argv
)
<
2
){
$this
->
help
(
$argv
[
0
]);
printf
(
"please input help parameter
\n
"
);
exit
();
}
if
(
$argv
[
1
]
===
'stop'
){
$this
->
stop
();
}
else
if
(
$argv
[
1
]
===
'start'
){
$this
->
start
();
}
else
if
(
$argv
[
1
]
===
'restart'
){
$this
->
stop
();
$this
->
start
();
}
else
if
(
$argv
[
1
]
===
'status'
){
$this
->
status
();
}
else
if
(
$argv
[
1
]
===
'foreground'
){
$this
->
foreground
();
}
else
if
(
$argv
[
1
]
===
'reload'
){
$this
->
reload
();
}
else
{
$this
->
help
(
$argv
[
0
]);
}
}
}
$daemon
=
new
Daemon
(
80
,
80
,
new
Test
());
$daemon
->
main
(
$argv
);
scripts/crontab/push/runRedisPush.php
View file @
9a4106ae
...
...
@@ -92,8 +92,9 @@ class runRedisPush
private
function
reload
(){
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
posix_kill
(
$pid
,
SIGUSR1
);
//posix_kill(posix_getpid(), SIGHUP);
posix_kill
(
$pid
,
SIGHUP
);
//
posix_kill($pid, SIGHUP);
}
}
protected
function
restart
(){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment