Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can possibly be a memory leak in php and how to investigate it?

I'm using Codeigniter framework (development version from github) for one of my projects. Project itself is not big just a few controllers and models and I have a memory leak. In 12 hours my rams constantly go up and i have to restart php5-fpm to clean them. Where should I start looking for memory leak? I mean is it loops or variables and what tools can I use for this to investigate?

like image 891
d4mn Avatar asked Apr 10 '14 08:04

d4mn


People also ask

Where can I find a memory leak?

To find a memory leak, look at how much RAM the system is using. The Resource Monitor in Windows can be used to accomplish this. In Windows 8.1 and Windows 10: To open the Run dialogue, press Windows+R, then type "resmon" and click OK.

What are memory leaks in PHP?

What is a memory leak in PHP? A memory leak in PHP is a condition that causes sections of code to continue using memory even though that memory is no longer needed.

What could be the possible cause of memory leaks?

Memory leak occurs when programmers create a memory in heap and forget to delete it. The consequences of memory leak is that it reduces the performance of the computer by reducing the amount of available memory.


2 Answers

A very old question, but for those facing this problem (since it is still a problem for some of us using CodeIgniter)... per the developer: By default, CodeIgniter keeps an array containing your history of queries.

Look into setting save_queries to false in your database configuration.

I had the same problem with a work project and this dramatically reduced our memory usage.

like image 148
kungphu Avatar answered Nov 15 '22 18:11

kungphu


If you need to find the exact cause of your memory leak, I will suggest you to use a memory profiler like XHProf.

This is the best way to debug the php scripts and what is the cause of memory leak.

like image 42
cedzz Avatar answered Nov 15 '22 19:11

cedzz