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
a9b7e8d1
Commit
a9b7e8d1
authored
Jun 18, 2021
by
yujiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:change mon
parent
8902bf18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
16 deletions
+14
-16
Request.php
src/Http/Request.php
+5
-4
MonUtil.php
src/Mon/MonUtil.php
+9
-12
No files found.
src/Http/Request.php
View file @
a9b7e8d1
...
...
@@ -107,11 +107,12 @@ class Request
* @param array $headers 自定义headers
* @param int $retry 重试次数
* @param bool $use_mon 是否使用监控打点(默认是)
* @param string $module 模块名
* @param string $proxy 代理(比如http://192.11.222.124:8000)
* @return array
* @throws
*/
public
function
post
(
$url
,
$params
=
[],
$timeout
=
0
,
$content_type
=
''
,
$headers
=
[],
$retry
=
0
,
$use_mon
=
''
,
$proxy
=
''
)
public
function
post
(
$url
,
$params
=
[],
$timeout
=
0
,
$content_type
=
''
,
$headers
=
[],
$retry
=
0
,
$use_mon
=
true
,
$module
=
''
,
$proxy
=
''
)
{
try
{
//验参
...
...
@@ -145,10 +146,10 @@ class Request
if
(
!
empty
(
$proxy
))
{
$options
[
'proxy'
]
=
$proxy
;
}
$options
[
'on_stats'
]
=
function
(
TransferStats
$stats
)
use
(
$use_mon
,
$url
)
{
$options
[
'on_stats'
]
=
function
(
TransferStats
$stats
)
use
(
$use_mon
,
$url
,
$module
)
{
$this
->
result
[
'http_code'
]
=
$stats
->
getHandlerStat
(
'http_code'
);
if
(
!
empty
(
$use_mon
)
)
{
MonUtil
::
proxyMon
(
$url
,
$stats
->
getHandlerStat
(
'http_code'
),
$
use_mon
,
round
(
$stats
->
getHandlerStat
(
'total_time'
),
4
)
*
1000
);
if
(
$use_mon
)
{
MonUtil
::
proxyMon
(
$url
,
$stats
->
getHandlerStat
(
'http_code'
),
$
module
,
round
(
$stats
->
getHandlerStat
(
'total_time'
),
4
)
*
1000
);
}
};
//异步post请求
...
...
src/Mon/MonUtil.php
View file @
a9b7e8d1
...
...
@@ -53,23 +53,20 @@ class MonUtil{
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
,
'?'
);
if
(
$index
!=
0
){
$preg_uri
=
substr
(
$url
,
0
,
$index
);
}
else
{
$preg_uri
=
$url
;
}
//截取请求第三方服务的uri
$parse_url
=
parse_url
(
$url
);
$preg_uri
=
$parse_url
[
'path'
]
??
$url
;
//替换$uri中的"."为"_", ":"为"_", "/"为"-"
$request_uri
=
str_replace
(
array
(
"."
,
":"
,
"/"
),
array
(
"_"
,
"_"
,
"-"
),
$preg_uri
);
$request_module
=
str_replace
(
array
(
"."
,
":"
,
"/"
),
array
(
"_"
,
"_"
,
"-"
),
$parse_url
[
'host'
]);
if
(
empty
(
$module
))
{
//默认取url 中的域名作为module
$module
=
$request_module
??
'other_depent'
;
}
//接口返回状态码打点
if
(
!
empty
(
$code
)
&&
is_numeric
(
$code
)){
$result
=
self
::
counting
(
$module
.
"."
.
(
string
)
$request_uri
,
(
string
)
$code
,
1
)
.
"
\n
"
;
...
...
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