Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-api-client
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-api-client
Commits
44633a57
Commit
44633a57
authored
5 months ago
by
Grzegorz Rola
Browse files
Options
Downloads
Patches
Plain Diff
bugfix(logger): memory consumption
parent
1c489b81
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!7
bugfix(logger): memory consumption
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+4
-0
4 additions, 0 deletions
CHANGELOG.md
src/Client/ClientImplementation.php
+20
-8
20 additions, 8 deletions
src/Client/ClientImplementation.php
with
24 additions
and
8 deletions
CHANGELOG.md
+
4
−
0
View file @
44633a57
### [1.2.2] - 2024-11-25
### Fixed
-
Memory consumption in api client - logger calls consumes memory, specially when large responses are logged
## [1.2.1] - 2020-12-08
### Fixed
-
default headers should overwrite build in headers
...
...
This diff is collapsed.
Click to expand it.
src/Client/ClientImplementation.php
+
20
−
8
View file @
44633a57
...
...
@@ -4,6 +4,7 @@ namespace WPDesk\ApiClient\Client;
use
Psr\Log\LoggerAwareInterface
;
use
Psr\Log\LoggerInterface
;
use
Psr\Log\NullLogger
;
use
WPDesk\HttpClient\HttpClient
;
use
WPDesk\HttpClient\HttpClientResponse
;
use
WPDesk\ApiClient\Request\Request
;
...
...
@@ -36,6 +37,9 @@ class ClientImplementation implements Client, LoggerAwareInterface
/** @var int */
private
$timeout
;
/** @var bool */
private
$is_logger_available
=
false
;
/**
* Client constructor.
* @param HttpClient $client
...
...
@@ -59,6 +63,7 @@ class ClientImplementation implements Client, LoggerAwareInterface
$this
->
apiUrl
=
$apiUri
;
$this
->
defaultRequestHeaders
=
$defaultRequestHeaders
;
$this
->
timeout
=
$timeout
;
$this
->
is_logger_available
=
!
$logger
instanceof
NullLogger
;
}
/**
...
...
@@ -70,8 +75,10 @@ class ClientImplementation implements Client, LoggerAwareInterface
*/
public
function
sendRequest
(
Request
$request
)
{
$this
->
logger
->
debug
(
"Sends request with METHOD:
{
$request
->
getMethod
()
}
; to ENDPOINT
{
$request
->
getEndpoint
()
}
"
,
$this
->
getLoggerContext
());
if
(
$this
->
is_logger_available
)
{
$this
->
logger
->
debug
(
"Sends request with METHOD:
{
$request
->
getMethod
()
}
; to ENDPOINT
{
$request
->
getEndpoint
()
}
"
,
$this
->
getLoggerContext
());
}
try
{
$httpResponse
=
$this
->
client
->
send
(
$fullUrl
=
$this
->
prepareFullUrl
(
$request
),
...
...
@@ -81,11 +88,16 @@ class ClientImplementation implements Client, LoggerAwareInterface
$this
->
timeout
);
$this
->
logger
->
debug
(
"Sent request with: URL:
{
$fullUrl
}
;
\n
METHOD:
{
$method
}
;
\n
BODY:
{
$body
}
;
\n
"
.
"HEADERS: "
.
json_encode
(
$headers
)
.
"
\n\n
and got response as CODE:
{
$httpResponse
->
getResponseCode
()
}
;
\n
"
.
"with RESPONSE BODY
{
$httpResponse
->
getBody
()
}
"
,
$this
->
getLoggerContext
());
if
(
$this
->
is_logger_available
)
{
$this
->
logger
->
debug
(
"Sent request with: URL:
{
$fullUrl
}
;
\n
METHOD:
{
$method
}
;
\n
BODY:
{
$body
}
;
\n
"
.
"HEADERS: "
.
json_encode
(
$headers
)
.
"
\n\n
and got response as CODE:
{
$httpResponse
->
getResponseCode
()
}
;
\n
"
.
"with RESPONSE BODY
{
$httpResponse
->
getBody
()
}
"
,
$this
->
getLoggerContext
()
);
}
return
$this
->
mapHttpResponseToApiResponse
(
$httpResponse
);
...
...
@@ -218,4 +230,4 @@ class ClientImplementation implements Client, LoggerAwareInterface
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment