Approximating PHP variable sizes in memory
JUL
22
You ever become curious about how much memory your fancy variable is using in your php script? Although there is no direct function to tell you the usage of a specific variable, you can infer an approximation using memory_get_usage().
It is simple, call memory_get_usage() once and store the result. Set your variable up and then call memory_get_usage() again and get the difference. There are many factors that affect memory though so beware this is just an approximation.
$startmem = memory_get_usage();
$var = "Variable";
echo memory_get_usage() - $startmem;