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
1ebb80bf
Commit
1ebb80bf
authored
Jun 16, 2021
by
cuiweifeng
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.yidian-inc.com/bp/php_utils
parents
53e93d00
9b3b9c7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
3 deletions
+76
-3
Request.php
src/Http/Request.php
+76
-3
No files found.
src/Http/Request.php
View file @
1ebb80bf
...
...
@@ -265,8 +265,76 @@ class Request
}
return
$ch
;
}
static
function
NEW_CURL
(
$url
,
$timeout
,
$retries
,
$headers
,
$post
=
false
,
$proxy
=
false
,
$has_curl_file
=
null
,
$method
=
'GET'
,
$curl_opts
=
array
())
{
$use_mon
=
false
;
//是否使用监控打点服务标志
//$proxy 取值为true,表示依赖第三方服务,要进行监控打点
if
(
$proxy
==
true
){
$use_mon
=
true
;
$proxy
=
false
;
}
$ch
=
self
::
CURL
(
$url
,
$timeout
,
$headers
,
$post
,
$proxy
,
$has_curl_file
,
$method
,
$curl_opts
);
$result
=
false
;
if
(
is_resource
(
$ch
)
===
true
)
{
while
((
$result
===
false
)
&&
(
$retries
--
>
0
))
{
$result
=
curl_exec
(
$ch
);
}
if
(
curl_errno
(
$ch
)
!==
0
)
{
$GLOBALS
[
'ERROR_MESSAGE'
]
=
curl_error
(
$ch
);
}
$GLOBALS
[
'HTTP_CODE'
]
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
if
(
isset
(
$GLOBALS
[
'ENABLE_HEADER_REQUEST_TIME'
])
)
{
$GLOBALS
[
'BELENDER_CURL_INFO'
]
=
curl_getinfo
(
$ch
);
//在返回header中添加blender响应时间
$GLOBALS
[
'DEPENDENT-REQUEST-TIME'
]
=
round
(
curl_getinfo
(
$ch
,
CURLINFO_TOTAL_TIME
),
4
)
.
'|'
.
round
(
curl_getinfo
(
$ch
,
CURLINFO_NAMELOOKUP_TIME
),
4
)
.
'|'
.
round
(
curl_getinfo
(
$ch
,
CURLINFO_CONNECT_TIME
),
4
);
$GLOBALS
[
'DEPENDENT-REQUEST'
]
=
array
(
'url'
=>
$url
,
'method'
=>
$method
,
'body'
=>
$post
);
$GLOBALS
[
'DEPENDENT-URI'
]
=
parse_url
(
$url
,
PHP_URL_PATH
);
if
(
$GLOBALS
[
'HTTP_CODE'
]
===
0
)
{
$GLOBALS
[
'DEPENDENT-STATUS'
]
=
'timeout'
;
}
else
if
(
$GLOBALS
[
'HTTP_CODE'
]
!==
200
)
{
$GLOBALS
[
'DEPENDENT-STATUS'
]
=
'5xx'
;
}
else
{
$GLOBALS
[
'DEPENDENT-STATUS'
]
=
'normal'
;
}
}
// //监控打点,模块名默认为第三方服务url,指标为请求返回的HTTP_code与总响应时间
// //HTTP_CODE如果未设置,默认为-999
// if($use_mon){
// MonUtil::proxy_mon($url,
// isset($GLOBALS['HTTP_CODE']) ? $GLOBALS['HTTP_CODE'] : -999,
// false,
// round(curl_getinfo($ch, CURLINFO_TOTAL_TIME),4) * 1000
// );
// }
unset
(
$GLOBALS
[
'ENABLE_HEADER_REQUEST_TIME'
]);
// if ($post === false)
// {
// write_log($url, curl_errno($ch), curl_error($ch), __LINE__, __FILE__, '', $result);
// }
// else
// {
// write_log($url, curl_errno($ch), curl_error($ch), __LINE__, __FILE__, 'POST body '.var_export($post, true), $result);
// }
curl_close
(
$ch
);
}
return
$result
;
}
public
function
put
(
$url
,
$params
=
[],
$timeout
=
0
,
$content_type
=
''
,
$headers
=
[],
$retry
=
0
,
$use_mon
=
true
,
$proxy
=
''
)
{
try
{
...
...
@@ -287,7 +355,7 @@ class Request
$client
=
(
new
Base
())
->
initClient
(
$config
,
$url
,
$params
);
//构造配置
if
(
!
empty
(
$params
))
{
if
(
$content_type
==
'json'
)
{
...
...
@@ -405,6 +473,11 @@ class Request
}
}
public
function
CURL_POST
(
$url
,
$post
,
$timeout
=
10000
,
$retries
=
1
,
$headers
=
false
,
$proxy
=
false
,
$curl_opts
=
array
())
{
return
self
::
NEW_CURL
(
$url
,
$timeout
,
$retries
,
$headers
,
$post
,
$proxy
,
null
,
'POST'
,
$curl_opts
);
}
/**
* 并发执行get请求
* @param array $urls [0=>xxx,1=>xxx]
...
...
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