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
bcba6f64
Commit
bcba6f64
authored
Jul 13, 2021
by
mengweifu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: HttpUtil
parent
a69c1304
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
HttpUtil.php
src/Http/HttpUtil.php
+27
-4
No files found.
src/Http/HttpUtil.php
View file @
bcba6f64
...
@@ -25,6 +25,8 @@ use Api\PhpUtils\Mon\MonUtil;
...
@@ -25,6 +25,8 @@ use Api\PhpUtils\Mon\MonUtil;
class
HttpUtil
class
HttpUtil
{
{
private
const
CODE_SUCCESS
=
0
;
private
const
CODE_FAIL
=
999999
;
static
function
HEAD
(
$url
,
$timeout
=
10000
,
$retries
=
1
,
$headers
=
false
,
$proxy
=
false
)
static
function
HEAD
(
$url
,
$timeout
=
10000
,
$retries
=
1
,
$headers
=
false
,
$proxy
=
false
)
{
{
...
@@ -53,7 +55,12 @@ class HttpUtil
...
@@ -53,7 +55,12 @@ class HttpUtil
{
{
$ch
=
self
::
CH
(
$url
,
$timeout
,
$headers
,
$post
,
$proxy
,
$method
,
$curl_opts
);
$ch
=
self
::
CH
(
$url
,
$timeout
,
$headers
,
$post
,
$proxy
,
$method
,
$curl_opts
);
$result
=
false
;
$result
=
''
;
//返回结果
$result_code
=
self
::
CODE_FAIL
;
//错误代码
$result_http_code
=
0
;
// http code
$error_msg
=
''
;
// ch error
if
(
is_resource
(
$ch
)
===
true
)
if
(
is_resource
(
$ch
)
===
true
)
{
{
...
@@ -61,6 +68,8 @@ class HttpUtil
...
@@ -61,6 +68,8 @@ class HttpUtil
{
{
$result
=
curl_exec
(
$ch
);
$result
=
curl_exec
(
$ch
);
}
}
// { todo
if
(
curl_errno
(
$ch
)
!==
0
)
if
(
curl_errno
(
$ch
)
!==
0
)
{
{
$GLOBALS
[
'ERROR_MESSAGE'
]
=
curl_error
(
$ch
);
$GLOBALS
[
'ERROR_MESSAGE'
]
=
curl_error
(
$ch
);
...
@@ -85,20 +94,34 @@ class HttpUtil
...
@@ -85,20 +94,34 @@ class HttpUtil
$GLOBALS
[
'DEPENDENT-STATUS'
]
=
'normal'
;
$GLOBALS
[
'DEPENDENT-STATUS'
]
=
'normal'
;
}
}
}
}
unset
(
$GLOBALS
[
'ENABLE_HEADER_REQUEST_TIME'
]);
unset
(
$GLOBALS
[
'ENABLE_HEADER_REQUEST_TIME'
]);
// }
// 监控
self
::
addMon
(
self
::
addMon
(
$url
,
$url
,
$GLOBALS
[
'HTTP_CODE'
]
??
-
999
,
$GLOBALS
[
'HTTP_CODE'
]
??
-
999
,
round
(
curl_getinfo
(
$ch
,
CURLINFO_TOTAL_TIME
),
4
)
*
1000
round
(
curl_getinfo
(
$ch
,
CURLINFO_TOTAL_TIME
),
4
)
*
1000
);
);
// 日志
self
::
addLog
(
$method
,
$url
,
$post
,
$result
);
self
::
addLog
(
$method
,
$url
,
$post
,
$result
);
if
(
curl_errno
(
$ch
)
!==
0
)
{
$error_msg
=
curl_error
(
$ch
);
}
$result_code
=
curl_errno
(
$ch
)
===
0
?
self
::
CODE_SUCCESS
:
self
::
CODE_FAIL
;
$result_http_code
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
curl_close
(
$ch
);
curl_close
(
$ch
);
}
}
return
$result
;
return
[
'code'
=>
$result_code
,
'response'
=>
empty
(
json_decode
(
$result
,
true
))
?
$result
:
json_decode
(
$result
,
true
),
'http_code'
=>
$result_http_code
,
'msg'
=>
$error_msg
,
];
}
}
/**
/**
...
...
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