Optimization of memory usage
Hello. I noticed a long time ago that the HTTP Client buffers the loaded documents into RAM because curl returns the response body as a string when the curl_exec() method is called.
This behavior sometimes leads to memory overflow and script crash. Personally, it affected me when using the WebDAV protocol (downloading large files). At that time, i found a workaround for myself. Today i want to share it with the community, as i see users encountering out of memory errors.
I wrote the test to load a document that exceeds the application's memory_limit.
In the current version of the code this test naturally fails with an error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 48238592 bytes) in sabre\http\lib\Client.php on line 589
After the merger of this PR test case will be passed.
Also i have run tests in the saber/dav package. After a clean installation, they did not work for me. With this PR, the test resuts is no different. It seems to me that backward compatibility for saber/dav has been preserved, but we should move towards getting rid of the use of deprecated methods.
From my position, the best solution would be to remove the obsolete code altogether and release a major version, but here you know better.
Breaks legacy capability: No headers are written to the response body. It is difficult to support both modes (with and without headers), although you can. But I would rather not spend energy on this support.
Codecov Report
Merging #167 (2703040) into master (bb27d1a) will increase coverage by
0.11%. The diff coverage is94.91%.
@@ Coverage Diff @@
## master #167 +/- ##
============================================
+ Coverage 93.63% 93.75% +0.11%
- Complexity 257 262 +5
============================================
Files 15 15
Lines 833 848 +15
============================================
+ Hits 780 795 +15
Misses 53 53
| Impacted Files | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| lib/Client.php | 85.02% <94.91%> (+1.16%) |
62.00 <11.00> (+5.00) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update bb27d1a...2703040. Read the comment docs.