PDA

View Full Version : Cron and PHP memory limit



joshkraemer
06-25-2009, 01:07 PM
I think this is a question for HM, but I will ask it here first and see if anyone is aware of this problem.

I have a php script that backs up all the MySQL databases in my account and emails them to me in a .tar file.

Recently, the size of the databases have required me to raise the php memory limit in my php.ini.

All works well, except when I try to run the same script (from the same file path) via cron instead of a web browser, I get the php fatal error: "Allowed memory size of 33554432 bytes exhausted." This indicates that HM's default php.ini settings are overriding the php.ini settings for my account (set to one php.ini file for all sub directories).

My cron command looks like this: /ramdisk/bin/php5 -q /home/username/public_html/maintenance/mysql/backup/backup_dbs.php

If I change /ramdisk/bin/php5 to php, the server will automatically change it back to /ramdisk/bin/php5 on the next script run.

Any thoughts or suggestions? Thanks!

shadmego
06-25-2009, 02:37 PM
Can you modify your script to do one database at a time, then dump the memory before the next database is backed up and emailed?

I seem to recall having some issues with memory sizes long ago.

My next question is how to you have php set up in your account? Are you using FastCGI, or php5 (single file) or just a regular setup?

If you are using a regular setup, and you php script is not directly inside your public_html folder, then you have to put a php.ini file inside the same folder your backup script is running, remembering to modify this second php.ini file with the memory size you need.

~regards

joshkraemer
06-25-2009, 03:29 PM
Can you modify your script to do one database at a time, then dump the memory before the next database is backed up and emailed?

Yes, I suppose so, but that would mean 6 backup emails every day. Also, the emails would use up more space.


My next question is how to you have php set up in your account? Are you using FastCGI, or php5 (single file) or just a regular setup?

php5 single php.ini setup

joshkraemer
06-25-2009, 05:09 PM
For the cron to use php.ini you need to add the following to the cron command

-c /home/username/public_html/php.ini

So it would look something like this:

/ramdisk/bin/php5 -c /home/username/public_html/php.ini -q /home/username/public_html/maintenance/mysql/backup/backup_dbs.php

Hope this helps someone!