Note that there are some explanatory texts on larger screens.

plurals
  1. POTracking Memory Usage in PHP
    primarykey
    data
    text
    <p>I'm trying to track the memory usage of a script that processes URLs. The basic idea is to check that there's a reasonable buffer before adding another URL to a cURL multi handler. I'm using a 'rolling cURL' concept that processes a URLs data as the multi handler is running. This means I can keep N connections active by adding a new URL from a pool each time an existing URL processes and is removed.</p> <p>I've used <code>memory_get_usage()</code> with some positive results. Adding the <code>real_usage</code> flag helped (not really clear on the difference between 'system' memory and 'emalloc' memory, but system shows larger numbers). <code>memory_get_usage()</code> does ramp up as URLs are added then down as the URL set is depleted. However, I just exceeded the 32M limit with my last memory check being ~18M. </p> <p>I poll the memory usage each time cURL multi signals a request has returned. Since multiple requests may return at the same time, there's a chance a bunch of URLs returned data at the same time and actually jumped the memory usage that 14M. However, if <code>memory_get_usage()</code> is accurate, I guess that's what's happening.</p> <p>[<strong>Update</strong>: Should have run more tests before asking I guess, increased php's memory limit (but left the 'safe' amount the same in the script) and the memory usage as reported did jump from below my self imposed limit of 25M to over 32M. Then, as expected slowly ramped down as URLs where not added. But I'll leave the question up: Is this the right way to do this?]</p> <p>Can I trust <code>memory_get_usage()</code> in this way? Are there better alternative methods for getting memory usage (I've seen some scripts parse the output of shell commands)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload