if i have a php background job, may need to run 4-5hours or more will it cause exception on memory_limit
+1
A:
In your php.ini increase the amount for memory_limit.
See http://www.ducea.com/2008/02/14/increase-php-memory-limit/
Pierre-Antoine LaFayette
2010-03-12 19:03:26
+1
A:
PHP has a very primitive memory manager and scripts are not designed to run for very long. You can update the memory limit like this:
<?php ini_set(“memory_limit”,”256M”); ?>
But you will probably still have memory problems. You could try adding a ton of unset()'s to your script and this can help a bit. But the memory leaks are probably in PHP and its C/C++ extensions which you can't control. In the past I have had to rewrite background tasks in Java.
Rook
2010-03-12 19:03:37
actually my script is very simple, get email data from db and send them out and sleep 30 sec by every 20 email sentit is really really simple srcipt, so i have no idea to rewrite
2010-03-12 19:29:08
You could setup a cron job to run it every minute, have it execute for 20 email and then exit. This way the memory will always remain low and this is in line with how PHP wants it's scripts to run.
Rook
2010-03-12 19:34:59
A:
Check out the following PHP commands:
// Sets the max time in seconds the script can run
set_time_limit($sec);
// Increases the memory limit (default is 1.5mb)
ini_set("memory_limit", "256M");
St. John Johnson
2010-03-12 19:18:01
Then you have a serious memory leak. If you are passing objects/arrays into repetitive functions, be aware you are copying that data into a new variable. Think about using some globals instead.
St. John Johnson
2010-03-12 19:33:11