Reduce memory when parsing large feeds#672
Merged
mblaney merged 1 commit intosimplepie:masterfrom Feb 20, 2021
Merged
Conversation
Upstream PR for FreshRSS/FreshRSS#3416 (use case is 12MB+ feed) Use the approach recommended by https://php.net/xml-parse#example-5983 for parsing documents that can potentially be large, because parsing a whole document in one go takes a lot of memory. No change in parsing approach compared to now for feeds up to 1MB (i.e. most feeds are unchanged - in my list of 173 test feeds, only one is larger than 1MB). Larger feeds will be parsed in more than one iteration (no functional difference). Using the php://temp as defined in https://php.net/wrappers.php fully in memory for feeds up to 2MB (by default) then using system's temp directory https://php.net/sys-get-temp-dir There is a test for badly configured systems with an unwriteable temp directory for which we only use php://memory (only in-memory even if it does not fit) Credits to @Kiblyn11 for the idea and the original PR.
Alkarex
commented
Feb 17, 2021
|
|
||
| // Parse! | ||
| if (!xml_parse($xml, $data, true)) | ||
| $wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory'; |
Contributor
Author
There was a problem hiding this comment.
Can be simplified by always using php://memory at the cost of not being able to parse just as large feeds
Member
|
this looks great, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream PR for FreshRSS/FreshRSS#3416 (use case is 12MB+ feed)
Use the approach recommended by https://php.net/xml-parse#example-5983 for parsing documents that can potentially be large, because parsing a whole document in one go takes a lot of memory.
No change in parsing approach compared to now for feeds up to 1MB (i.e. most feeds are unchanged - in my list of 173 test feeds, only one is larger than 1MB). Larger feeds will be parsed in more than one iteration (no functional difference).
Using the php://temp as defined in https://php.net/wrappers.php fully in memory for feeds up to 2MB (by default) then using system's temp directory https://php.net/sys-get-temp-dir
There is a test for badly configured systems with an unwritable temp directory for which we only use php://memory (only in-memory even if it does not fit)
Credits to @Kiblyn11 for the idea and the original PR.