I recently decreased the PHP memory_limit used by our web server to 128 MB. This was done to increase the scalability of our web site.
Since decreasing our memory limit, we are now receiving the following PHP error message when Elysia Cron is used to generate database backups via Backup Migrate:
[Thu Mar 01 09:15:07.409773 2018] [proxy_fcgi:error] [pid 9884:tid 140172146464512] [client 107.23.36.77:52886] AH01071: Got error 'PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes) in /var/www/xxx_company/html/includes/database/database.inc on line 2227\nPHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in /var/www/xxx_company/html/includes/database/database.inc:2227\nStack trace:\n#0 /var/www/xxx_company/html/includes/database/database.inc(2227): PDOStatement->execute(Array)\n#1 /var/www/xxx_company/html/includes/database/database.inc(697): DatabaseStatementBase->execute(Array, Array)\n#2 /var/www/xxx_company/html/includes/database/select.inc(1280): DatabaseConnection->query('SELECT ec.name ...', Array, Array)\n#3 /var/www/xxx_company/html/sites/all/modules/contrib/elysia_cron/elysia_cron.module(364): SelectQuery->execute()\n#4 /var/www/xxx_company/html/sites/all/modules/contrib/elysia_cron/elysia_cron.module(486): elysia_cron_get(':Alternate', true, 'running', 0, false)\n#...\n'
Rather than increase the PHP memory_limit used by our web site, I would like to conditionally set the memory limit used when Backup Migrate generates database backups. This will give Backup Migrate the memory it needs when database backups are generated, while preserving a low memory limit for all other PHP scripts executed by our web site.
Patch to follow.
Thank you,
Gordon
Comments
Comment #2
gturnbull CreditAttribution: gturnbull as a volunteer commentedComment #3
gturnbull CreditAttribution: gturnbull as a volunteer commentedComment #4
DamienMcKennaComment #6
DamienMcKennaThanks for the idea and for taking the time to write the patch. While this could be a good feature for many sites, I don't like setting the default to 2gb - many VPSes would collapse under that, never mind shared web hosts.
What I'd suggest is: use a lower default, e.g. 512M or even 256M; add an extra check to see if the ini_set() function is available (it can be disabled); add some better logic to convert the strings to numbers and compare the raw numbers, otherwise if someone's site had the value set to "1G" it'd change it to 2G.
Comment #7
gturnbull CreditAttribution: gturnbull as a volunteer commentedHi Damien,
Thank you for taking the time to review my patch. I have created an updated version based on your suggestions. I hope this patch proves helpful to yourself and others.
Updated patch to follow.
Thank you,
Gordon
Comment #8
gturnbull CreditAttribution: gturnbull as a volunteer commentedComment #9
gturnbull CreditAttribution: gturnbull as a volunteer commentedComment #10
DamienMcKennaTwo quick things:
Comment #11
gturnbull CreditAttribution: gturnbull as a volunteer commentedHi Damien,
Thank you for your feedback. Here is an updated patch.
What do you think?
Thank you,
Gordon
Comment #12
gturnbull CreditAttribution: gturnbull as a volunteer commentedComment #13
gturnbull CreditAttribution: gturnbull as a volunteer commentedUpdated my patch to better reflect Drupal coding standards.
Please review and let me know if this patch could be included in the next release.
Thank you,
Gordon
Comment #14
gturnbull CreditAttribution: gturnbull as a volunteer commentedI installed the Coder module and used it to identify coding standards problems previously overlooked. Updated patch attached. This should do it!
Please let me know what you think.
Thank you,
Gordon
Comment #15
Alex Bukach CreditAttribution: Alex Bukach commented#14 works fine for me. Thanks @gturnbull!
Comment #16
3liChiming in to say that #14 has also worked for me.
Comment #17
joelpittetGood idea thanks @gturnbull. I have a sneaky feeling I know which site that's for;)
Comment #18
DamienMcKennaRerolled, and I added a note to the README.txt file.
Comment #20
DamienMcKennaThe tests actually pass. Not sure what's going on.
Comment #21
DamienMcKennaCommitted.
Comment #23
DamienMcKenna