Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
php_utils
Project
Project
Details
Activity
Releases
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
bp
php_utils
Commits
8902bf18
Commit
8902bf18
authored
Jun 18, 2021
by
yujiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:add mon
parent
474c0159
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
Request.php
src/Http/Request.php
+2
-2
MonUtil.php
src/Mon/MonUtil.php
+9
-4
No files found.
src/Http/Request.php
View file @
8902bf18
...
...
@@ -111,7 +111,7 @@ class Request
* @return array
* @throws
*/
public
function
post
(
$url
,
$params
=
[],
$timeout
=
0
,
$content_type
=
''
,
$headers
=
[],
$retry
=
0
,
$use_mon
=
true
,
$proxy
=
''
)
public
function
post
(
$url
,
$params
=
[],
$timeout
=
0
,
$content_type
=
''
,
$headers
=
[],
$retry
=
0
,
$use_mon
=
''
,
$proxy
=
''
)
{
try
{
//验参
...
...
@@ -148,7 +148,7 @@ class Request
$options
[
'on_stats'
]
=
function
(
TransferStats
$stats
)
use
(
$use_mon
,
$url
)
{
$this
->
result
[
'http_code'
]
=
$stats
->
getHandlerStat
(
'http_code'
);
if
(
!
empty
(
$use_mon
))
{
MonUtil
::
proxyMon
(
$u
se_mon
,
$url
,
$stats
->
getHandlerStat
(
'http_code'
),
round
(
$stats
->
getHandlerStat
(
'total_time'
),
4
)
*
1000
);
MonUtil
::
proxyMon
(
$u
rl
,
$stats
->
getHandlerStat
(
'http_code'
),
$use_mon
,
round
(
$stats
->
getHandlerStat
(
'total_time'
),
4
)
*
1000
);
}
};
//异步post请求
...
...
src/Mon/MonUtil.php
View file @
8902bf18
...
...
@@ -50,9 +50,14 @@ class MonUtil{
* @param int $request_time 请求总时长
* @return string 打点信息或""
*/
public
static
function
proxyMon
(
$
module
,
$url
,
$code
,
$request_time
=
-
899
){
public
static
function
proxyMon
(
$
url
,
$code
,
$module
=
''
,
$request_time
=
-
899
){
$result
=
""
;
if
(
empty
(
$module
))
{
//默认按照域名当作模块名称
$module
=
isset
(
$_SERVER
[
'SERVER_NAME'
])
?
str_replace
(
"."
,
"_"
,
$_SERVER
[
'SERVER_NAME'
])
:
'other'
;
}
if
(
is_string
(
$url
)
&&
!
empty
(
$url
)){
//截取请求第三方服务的uri
$index
=
strpos
(
$url
,
'?'
);
...
...
@@ -67,14 +72,14 @@ class MonUtil{
//接口返回状态码打点
if
(
!
empty
(
$code
)
&&
is_numeric
(
$code
)){
$result
=
MonUtil
::
counting
(
$module
.
"."
.
strval
(
$request_uri
),
strval
(
$code
)
,
1
)
.
"
\n
"
;
$result
=
self
::
counting
(
$module
.
"."
.
(
string
)
$request_uri
,
(
string
)
$code
,
1
)
.
"
\n
"
;
}
else
{
$result
=
MonUtil
::
counting
(
$module
.
"."
.
strval
(
$request_uri
),
strval
(
-
999
)
,
1
)
.
"
\n
"
;
$result
=
self
::
counting
(
$module
.
"."
.
(
string
)
$request_uri
,
(
string
)
-
999
,
1
)
.
"
\n
"
;
}
//接口请求响应总时间打点
if
(
!
empty
(
$request_time
)
&&
is_numeric
(
$request_time
)
&&
$request_time
!=
-
899
){
$result
=
$result
.
MonUtil
::
timing
(
strval
(
$request_uri
),
"TotalTime"
,
$request_time
);
$result
.=
self
::
timing
((
string
)
$request_uri
,
"TotalTime"
,
$request_time
);
}
}
return
$result
;
...
...
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