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
d0e1aa8a
Commit
d0e1aa8a
authored
Aug 11, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: request 增加 traceId
parent
94791b89
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
HttpUtil.php
src/Http/HttpUtil.php
+9
-0
Request.php
src/Http/Request.php
+13
-0
No files found.
src/Http/HttpUtil.php
View file @
d0e1aa8a
...
@@ -21,6 +21,7 @@ namespace Api\PhpUtils\Http;
...
@@ -21,6 +21,7 @@ namespace Api\PhpUtils\Http;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\Tracer
;
use
Api\PhpUtils\Mon\MonUtil
;
use
Api\PhpUtils\Mon\MonUtil
;
class
HttpUtil
class
HttpUtil
...
@@ -58,6 +59,10 @@ class HttpUtil
...
@@ -58,6 +59,10 @@ class HttpUtil
*/
*/
public
static
function
get
(
string
$url
,
array
$params
=
[],
int
$timeout
=
10000
,
int
$retries
=
1
,
array
$headers
=
[],
string
$proxy
=
''
,
array
$curl_opts
=
[])
:
array
public
static
function
get
(
string
$url
,
array
$params
=
[],
int
$timeout
=
10000
,
int
$retries
=
1
,
array
$headers
=
[],
string
$proxy
=
''
,
array
$curl_opts
=
[])
:
array
{
{
// 增加traceId
if
(
is_array
(
$headers
))
{
$headers
[
'X-TRACE-ID'
]
=
Tracer
::
getTraceId
();
}
$url
=
$url
.
"?"
.
http_build_query
(
$params
);
$url
=
$url
.
"?"
.
http_build_query
(
$params
);
return
self
::
curl
(
$url
,
$timeout
,
$retries
,
$headers
,
[],
$proxy
,
'GET'
,
$curl_opts
);
return
self
::
curl
(
$url
,
$timeout
,
$retries
,
$headers
,
[],
$proxy
,
'GET'
,
$curl_opts
);
}
}
...
@@ -90,6 +95,10 @@ class HttpUtil
...
@@ -90,6 +95,10 @@ class HttpUtil
*/
*/
public
static
function
post
(
string
$url
,
$post
,
int
$timeout
=
10000
,
int
$retries
=
1
,
array
$headers
=
[],
string
$proxy
=
''
,
array
$curl_opts
=
[])
:
array
public
static
function
post
(
string
$url
,
$post
,
int
$timeout
=
10000
,
int
$retries
=
1
,
array
$headers
=
[],
string
$proxy
=
''
,
array
$curl_opts
=
[])
:
array
{
{
// 增加traceId
if
(
is_array
(
$headers
))
{
$headers
[
'X-TRACE-ID'
]
=
Tracer
::
getTraceId
();
}
return
self
::
curl
(
$url
,
$timeout
,
$retries
,
$headers
,
$post
,
$proxy
,
'POST'
,
$curl_opts
);
return
self
::
curl
(
$url
,
$timeout
,
$retries
,
$headers
,
$post
,
$proxy
,
'POST'
,
$curl_opts
);
}
}
...
...
src/Http/Request.php
View file @
d0e1aa8a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
Api\PhpUtils\Http
;
namespace
Api\PhpUtils\Http
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\Tracer
;
use
Api\PhpUtils\Mon\MonUtil
;
use
Api\PhpUtils\Mon\MonUtil
;
use
GuzzleHttp\Exception\RequestException
;
use
GuzzleHttp\Exception\RequestException
;
use
GuzzleHttp\Exception\TransferException
;
use
GuzzleHttp\Exception\TransferException
;
...
@@ -64,6 +65,12 @@ class Request
...
@@ -64,6 +65,12 @@ class Request
if
(
!
empty
(
$timeout
))
{
if
(
!
empty
(
$timeout
))
{
$options
[
'timeout'
]
=
$timeout
/
1000
;
$options
[
'timeout'
]
=
$timeout
/
1000
;
}
}
// 增加traceId
if
(
is_array
(
$headers
))
{
$headers
[
'X-TRACE-ID'
]
=
Tracer
::
getTraceId
();
}
if
(
!
empty
(
$headers
))
{
if
(
!
empty
(
$headers
))
{
$options
[
'headers'
]
=
$headers
;
$options
[
'headers'
]
=
$headers
;
}
}
...
@@ -140,6 +147,12 @@ class Request
...
@@ -140,6 +147,12 @@ class Request
if
(
!
empty
(
$timeout
))
{
if
(
!
empty
(
$timeout
))
{
$options
[
'timeout'
]
=
$timeout
/
1000
;
$options
[
'timeout'
]
=
$timeout
/
1000
;
}
}
// 增加traceId
if
(
is_array
(
$headers
))
{
$headers
[
'X-TRACE-ID'
]
=
Tracer
::
getTraceId
();
}
if
(
!
empty
(
$headers
))
{
if
(
!
empty
(
$headers
))
{
$options
[
'headers'
]
=
$headers
;
$options
[
'headers'
]
=
$headers
;
}
}
...
...
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