How to Check Memory Usage in PHP

To check memory usage, PHP provides an inbuilt function memory_get_usage(). This function returns the amount of memory allocated to a PHP script.

** memory_get_usage() function returns the amount of memory allocated to your PHP script in bytes.

To convert them in KB – memory_get_usage/1024

To convert them in MB – memory_get_usage/1048576

PHP MCQ

PHP Built-in Web-Server

Subscribe Our Tutorials

Get Latest Updates on Facebook

How to Check Memory Usage in PHP by memory_get_usage() Method

Let’s demonstrate this through an example.

Here is a simple PHP script, which creates an instance of MongoDB.

It is very useful to know how much memory is allocated during your PHP script execution so that you can avoid Fatal Error: Allowed memory size exhausted.

Php.net Manual

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.