-
Notifications
You must be signed in to change notification settings - Fork 438
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
lessen memory usage #335
lessen memory usage #335
Conversation
76d046f
to
49b5848
Compare
49b5848
to
86f4951
Compare
@NiR- It is related to the issue I made. Unfortunatly I don't have any evidence for the increased memory usage. I only noticed it on my installation: when using the file_put_contents operation it was impossible to generate a large pdf because of memory errors. When using the debugger the error always happened on the file_put_contents instruction. When i replaced it with the three seperate instructions everything worked as it should. The idea of changing the instruction into three different ones came from a stackoverflow question |
According to https://blackfire.io/profiles/compare/78c2f364-0fe7-4e18-85c6-2ae517293d50/graph using Profiled script <?php
$data = file_get_contents('input.txt');
function write($data) {
// file_put_contents('output.txt', $data);
$handle = fopen('output.txt', 'w');
fwrite($handle, $data);
fclose($handle);
}
write($data); |
Thanks @fbourigault, that's what I was looking for :) Some more questions @JO0st, what's the source of the file content? Is it a stream? Because actually it feels weird that |
The data input is a string built in memory. The method gets called by snappy's generateFromHtml |
@JO0st Could you provide a full reproducer or at least the error message you got and your current snappy version please? |
The error message is Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 33096176 bytes) in /var/www/html/sites/all/modules/civicrm/packages/snappy/src/Knp/Snappy/AbstractGenerator.php on line 317. It gets created from from civicrm(https://github.com/civicrm/civicrm-core/blob/10bc9d11f88e9d7d5e321b9500013b2269fe9bf4/CRM/Utils/PDF/Utils.php#L234) . This is the string that gets fed into snappy. I stripped all personal content from it https://nextcloud.fock.be/index.php/s/tmoXwzd4a9Dtis6. The file is too big to attach it to github. |
The file you uploaded is 31.5MB and the size PHP is trying to allocate is also 31.5MB (33096176 / 1024 / 1024). I would say it's related to loading the html content into memory. snappy/src/Knp/Snappy/AbstractGenerator.php Line 317 in 144c4ec
The line 317 is a PHPDoc comment. So which version of snappy is used? |
i'm using the version supplied with civicrm. Unfortunatly they haven't documented which version they are using (https://github.com/civicrm/civicrm-packages/blob/faa4b03933b4d47a9a1098271b64405c81f4700e/VERSIONS.php#L110). However it looks like the snappy version in civicrm hasn't been updated in 6 years :( https://github.com/civicrm/civicrm-packages/tree/master/snappy |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
apperently file_put_contents uses more memory than the seperate actions it is executing according to http://php.net/manual/en/function.file-put-contents.php