Question

if i have a php background job, may need to run 4-5hours or more will it cause exception on memory_limit

Was it helpful?

Solution

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.

OTHER TIPS

In your php.ini increase the amount for memory_limit.

See http://www.ducea.com/2008/02/14/increase-php-memory-limit/

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");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top