How to calculate memory usage in PHP

I wrote a very large PHP file with a lot of variables and equations. Now I'm going to post it on my college website, but with our hosting there is a limit on memory consumption. There will be thousands of hits on this page.

So, I want to know the consumed memory of my PHP file when it is requested once, so that we can calculate the use of memory resources and based on this determine how to proceed.

+6
source share
3 answers

may be wrong, but apachebench can help you here. This will give you an idea of ​​how your colleges can handle the load.

http://httpd.apache.org/docs/2.0/programs/ab.html

0
source

If you use an autoloader for your classes, it may be useful to include this code at the beginning of the function:

function autoloader($class) { $memory = memory_get_usage (FALSE ); print ("Autoloading $class - memory is $memory<br>"); (autoloader code here) } 

As my application develops, this gives me a general idea of ​​the memory that my script uses. I never optimize my application to the very end, so each class is loaded individually, which is definitely useful to find out how much memory is used to load each of them.

Hope this helps someone :)

0
source

Source: https://habr.com/ru/post/888642/


All Articles