|
Friday 08 May 2009 11:58:57 am
Comment51105
I've ran into the same problem some days ago. adding more "memory-limit" to the script could do the trick, but it's not the best solution. my situation is like yours. we have to export some user data to cvs files. we started with 128M but when more users registered into the site, the problems started. now we have more than 65.000 registered users and even if you set memory-limit to 1GB the memory get exhausted. and it seems that the problem is not really an eZ one but a php problem with the memory management. i suggest to you do this. add a
$cli->output(memory_get_usage()) ;
at the end of every loop. you will see how this is value is increased every step. i mean if you expect a lot of users in your site next months, you'll probably get the problem again. Event if you unset all variables used, no matter if you change your foreach to for $i=0 ; $i<count($users)... memory will get exhausted. in a ideal world, php should free memory in every step, but it seems that it's not doing well. My workaround for this was to build some kinda batch process. i have two scripts, script1.php and script2.php. script1 is the one executed with the cron. it it something like
//get the total of users
do
{
//stuff here
} while $offset < total of users
in every loop script queries a record of a dummy table. at the first step that record is 0. script1 get that value and pass it to the script to via exec command. i mean something like
exec("script2.php --offset=$offset limit=100);
script2 get the offset param and do the subTreeByNodeId fetch. when offset is 0, it opens a file to write the results. when is not 0, it opens it for adding results.
when script2 end, it updates the dummy table and set the value to value + 100 script 1 get this value and pass it to script to until the value of the table is bigger than the total users we have. hope it helps
|