We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

why does the cli_task take so long time?

I run the same code in "cli task action" and "web controller action". The code is used to update data in MySQL. But when I use CLI to run the function, it takes about over 30 times as compared with the time calling from web.

I want to create cron jobs to update data automatically. But it's too slow calling from CLI. It happens both in CentOS 7 and OSX 10.10.3.

Phalcon 1.3.3

Thanks!



6.9k

The piece of code has many MySQL select and update operations. I guess it is because of the memory limit. How to set the memory limit when calling from CLI?



6.9k
edited Apr '15

I use memory_get_usage() to get the allocated memory. The function become obviously slow when the memory_get_usage()'s return value is over 100,000,000. The code runs more and more slowly with the memory_get_usage()'s return value increases.

memory_limit=512M in the php.ini.

memory_get_usage returns the current memory that your script is using, so if this is increasing it means you're not freeing memory, unset all big variables that are not necessary once used with unset ()



6.9k
edited Apr '15

memory_get_usage returns the current memory that your script is using, so if this is increasing it means you're not freeing memory, unset all big variables that are not necessary once used with unset ()

I have used unset() to free the big variables. But the allocated memory seems to be no effect. Calling from web allocates only about half of the memory allocated by calling by CLI. I don't know why CLI allocates so much memory and is there any other ways to free memory?

After the action running about 2.5 hours, the allocated memory is about 500,000,000. So why does the action run so slowly when the allocated memory is over 100,000,000 while the action could allocate over 500,000,000?

Thanks!

edited May '15

There aren't other ways to free memory, you can use unset (...$vars);, (unset) $var; (oops, I was wrong https://php.net/unset#example-5731) or $var = NULL;, all have the same effect. I would recommend you this reading https://blog.ircmaxell.com/2014/12/what-about-garbage.html

Also note that PHP CLI loads a different php.ini