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
7d0daeb2
Commit
7d0daeb2
authored
Jan 03, 2019
by
chenchuanwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run
parent
7e3d4041
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
159 additions
and
2 deletions
+159
-2
bridgeStart.php
scripts/crontab/push/bridgeStart.php
+136
-0
runRedisPush.php
scripts/crontab/push/runRedisPush.php
+23
-2
No files found.
scripts/crontab/push/bridgeStart.php
0 → 100644
View file @
7d0daeb2
<?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
runRedisPush
{
/* 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
());
}
}
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
]);
}
}
public
function
callback
(
$instance
,
$channelName
,
$message
){
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
$orderService
->
testPush
(
$message
);
}
private
function
start
()
{
$pid
=
$this
->
daemon
();
$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
();
}
protected
function
restart
(){
$this
->
stop
();
$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
);
}
public
function
main
(
$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
{
$this
->
help
(
$argv
[
0
]);
}
}
}
$cgse
=
new
runRedisPush
();
$cgse
->
main
(
$argv
);
\ No newline at end of file
scripts/crontab/push/runRedisPush.php
View file @
7d0daeb2
...
@@ -46,6 +46,14 @@ class runRedisPush
...
@@ -46,6 +46,14 @@ class runRedisPush
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
$orderService
=
\Business\Order\OrderServiceModel
::
getInstance
();
$orderService
->
testPush
(
$message
);
$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
()
private
function
start
()
{
{
$pid
=
$this
->
daemon
();
$pid
=
$this
->
daemon
();
...
@@ -60,6 +68,13 @@ class runRedisPush
...
@@ -60,6 +68,13 @@ class runRedisPush
$result
=
$redis
->
subscribe
(
array
(
'redisPublish'
),
array
(
$this
,
'callback'
));
$result
=
$redis
->
subscribe
(
array
(
'redisPublish'
),
array
(
$this
,
'callback'
));
}
}
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
(){
protected
function
restart
(){
$this
->
stop
();
$this
->
stop
();
$this
->
start
();
$this
->
start
();
...
@@ -79,9 +94,10 @@ class runRedisPush
...
@@ -79,9 +94,10 @@ class runRedisPush
{
{
printf
(
"%s start | stop | help | restart | reload
\n
"
,
$proc
);
printf
(
"%s start | stop | help | restart | reload
\n
"
,
$proc
);
}
}
private
$argv
;
public
function
main
(
$argv
)
public
function
main
(
$argv
)
{
{
$this
->
argv
=
$argv
;
if
(
count
(
$argv
)
<
2
)
{
if
(
count
(
$argv
)
<
2
)
{
printf
(
"please input help parameter
\n
"
);
printf
(
"please input help parameter
\n
"
);
exit
();
exit
();
...
@@ -93,7 +109,12 @@ class runRedisPush
...
@@ -93,7 +109,12 @@ class runRedisPush
$this
->
start
();
$this
->
start
();
}
else
if
(
$argv
[
1
]
===
'restart'
){
}
else
if
(
$argv
[
1
]
===
'restart'
){
$this
->
restart
();
$this
->
restart
();
}
else
{
}
else
if
(
$argv
[
1
]
===
'status'
){
$this
->
status
();
}
else
if
(
$argv
[
1
]
===
'reload'
){
$this
->
reload
();
}
else
{
$this
->
help
(
$argv
[
0
]);
$this
->
help
(
$argv
[
0
]);
}
}
}
}
...
...
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