Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if my PHP application is using too much memory?

I'm working on a PHP web application that let's users network with each other, book events, and message eachother. There's only about 100 users.

I set up the application on a VPS with Ubuntu 9.10, apache2, mysql 5 and php 5. I had 360 Mb of RAM, but upgraded to 720 MB.

Lately, my web application has been experiencing outages due to excessive memory usage. From what I can tell in error logs, it seems the server automatically kills apache processes that consume too much memory. As a result, I upgraded memory from 360 MB to 720 MB as a stop-gap measure.

So my question is, how do I go about resolving these outage issues? How do I know if my website's need for more memory is due to poor code or if it's part of the website's natural growth? What's the most efficient way to determine which PHP scripts consume the most memory?

like image 307
John Avatar asked Mar 16 '10 17:03

John


People also ask

How do I monitor PHP memory usage?

The memory_get_usage function can be used to track the memory usage. The 'malloc' function is not used for every block required, instead a big chunk of system memory is allocated and the environment variable is changed and managed internally.

How do I check my PHP memory limit?

ini file. Open your php. ini file then edit it using your favorite editor. Find the line: memory_limit = 32M.

What is a good PHP memory limit?

The right one for you depends on your system configuration. A typical appropriate memory limit for PHP running Drupal is 128MB per process; for sites with a lot of contributed modules or with high-memory pages, 256MB or even 512MB may be more appropriate.

How much memory does each PHP process consume?

Memory Limit is Not The Same as RAM While RAM is the total available memory, the memory limit is per PHP process. That means that your site can consume e.g 10 GB of RAM, with a memory limit of 256 MB.


1 Answers

Here is a tool that supports profiling PHP: http://xdebug.org/docs/profiler

like image 74
Achilles Avatar answered Sep 20 '22 13:09

Achilles