I am trying to track the memory usage of a script that processes URLs. The basic idea is to check for a reasonable buffer before adding another URL to the cURL multiprocessor. I use the concept of "roll cURL", which processes the URL data when the multiprocessor is running. This means that I can keep N connections active by adding a new URL from the pool each time an existing URL is processed and deleted.
I used memory_get_usage() with some positive results. Adding the real_usage flag helped (the difference between the "system" memory and the "emalloc" memory is not entirely clear, but the system shows large numbers). memory_get_usage() grows when URLs are added and then down as the set of URLs is exhausted. However, I just exceeded the 32M limit when my last memory check was ~ 18M.
I examine memory usage every time cURL multi signals return a request. Since multiple requests may return at the same time, it is likely that multiple URLs will return data at the same time and actually translate memory usage into 14M. However, if memory_get_usage() is accurate, I guess what happens.
[ Update . Should have run more tests before asking, I think the php memory limit was increased (but left the “safe” amount the same in the script), and the memory usage was reported to jump from below below my limit ranging from 25M to 32M. Then, as expected, slowly declined as URLs that were not added. But I will leave the question: is this the right way to do this?]
Can I trust memory_get_usage() this way? Are there any better alternative methods for using memory (I saw some scripts analyze shell command output)?
memory-management php memory
Tim Lytle Feb 18 '10 at 17:11 2010-02-18 17:11
source share