-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce memory footprint when parsing HTTP result #115
Conversation
24fbf06
to
8f227d1
Compare
Codecov Report
@@ Coverage Diff @@
## master #115 +/- ##
===========================================
+ Coverage 88.21% 93.5% +5.29%
- Complexity 242 250 +8
===========================================
Files 15 15
Lines 789 816 +27
===========================================
+ Hits 696 763 +67
+ Misses 93 53 -40
Continue to review full report at Codecov.
|
Really cool. Did you measure how much memory consumption improves with this fix? |
It save 1x memory copy depends on size of HTTP body. <?php
ini_set('memory_limit', '128M');
$response = str_repeat('a', 100 * pow(1024, 2));
echo 'peak usage: ' . memory_get_peak_usage() . PHP_EOL;
$responseBody = substr($response, 1); // Get called in parseCurlResult()
echo 'peak usage: ' . memory_get_peak_usage() . PHP_EOL; Output
|
48020a2
to
ef10ff6
Compare
Would throw an excpetion like following message PHPUnit\Framework\Exception: PHP Fatal error: Allowed memory size of 73400320 bytes exhausted (tried to allocate 31457312 bytes) in /home/gasolwu/Code/sabre-http/lib/Client.php on line 437
6f31a50
to
d41058d
Compare
In order to resolve sabre-io#82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue sabre-io#15 See sabre-io#115 (comment)
d41058d
to
0f657da
Compare
Let PHPUnit be quiet PHPUnit 7.5.1 by Sebastian Bergmann and contributors. Warning - The configuration file did not pass validation! The following problems have been detected: Line 8: - Element 'phpunit', attribute 'strict': The attribute 'strict' is not allowed. Test results may not be as expected. See sebastianbergmann/phpunit@78c8865
The feature needs to install additional package. Error: Package phpunit/php-invoker is required for enforcing time limits
0f657da
to
74ebd58
Compare
In order to resolve sabre-io#82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue sabre-io#15 See sabre-io#115 (comment)
In order to resolve sabre-io#82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue sabre-io#15 See sabre-io#115 (comment)
74ebd58
to
4e1daa6
Compare
Use local variable instead
4e1daa6
to
ab73d45
Compare
Fix error like TypeError: Return value of Sabre\HTTP\Client::curlExec() must be of the type string, boolean returned
ab73d45
to
3fe1452
Compare
any concerns? We are using inline alias for temporary fixes for a while, It is painful to maintain forked project on internal VCS hosting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, totally forgot this PR
In order to resolve #82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue #15 See #115 (comment)
Thx. Sorry for the long wait periode. Well done! |
In order to resolve #82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated
parseCurlResult
method which usesubstr
function to separate HTTP headers and body and create newmethod
parseCurlResponse
instead. We registerreceiveCurlHeader
method as callback function by curl_setopt usingCURLOPT_HEADERFUNCTION
option. See #115 (comment).This changes is not intended to resolve issue #15