note 55921 deleted from function.memory-get-usage by nikic

From: Date: Mon, 26 Nov 2018 21:05:37 +0000
Subject: note 55921 deleted from function.memory-get-usage by nikic
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209781@lists.php.net to get a copy of this message
Note Submitter: grey - greywyvern - com ---- If nothing else in the user notes below works for you, you can get a very (VERY) rough estimate of PHP memory usage by outputting the $GLOBALS array, stripping it of indentation whitespace, and counting the characters in the resulting string. This method has a very high overhead (to be expected), but works on all operating systems, regardless of whether or not they have the --enable-memory-limit config option set. I find that the syntax overhead of the print_r() statement roughly accounts for the PHP runtime base memory usage. The code below is set up to work on all arrays, not just the $GLOBALS array. Keep in mind that outside data referenced by resource IDs, such as database results and open file data, is not included in this total. <?php function array_size($arr) { ob_start(); print_r($arr); $mem = ob_get_contents(); ob_end_clean(); $mem = preg_replace("/\n +/", "", $mem); $mem = strlen($mem); return $mem; } $memEstimate = array_size($GLOBALS); ?> Use only if being off to either side by at least 20% is acceptible for your purposes.

« previous php.notes (#209781) next »