Skip to content
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

Optimization of memory usage #167

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

roxblnfk
Copy link

@roxblnfk roxblnfk commented Jan 11, 2021

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
Copy link

codecov bot commented Jan 11, 2021

Codecov Report

Merging #167 (2703040) into master (bb27d1a) will increase coverage by 0.11%.
The diff coverage is 94.91%.

Impacted file tree graph

@@             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 data
Powered by Codecov. Last update bb27d1a...2703040. Read the comment docs.

@roxblnfk roxblnfk marked this pull request as ready for review January 22, 2021 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant