Where could there be a memory leak in php and how to investigate it?

I am using the Codeigniter framework (development version from github) for one of my projects. The project itself is small, just a few controllers and models, and I have a memory leak. After 12 hours, my rams constantly rise, and I have to restart php5-fpm to clear them. Where should I start my memory leak search? I mean, are these loops or variables, and what tools can I use to do this to explore?

+8
php memory-leaks codeigniter
source share
3 answers

A very old question, but for those who are faced with this problem (since for some of us there is still a problem with CodeIgniter) ... for the developer: By default, CodeIgniter stores an array containing your query history.

Find the save_queries - false setting in your database settings.

I had the same problem with a working project, and this greatly reduced memory usage.

+8
source share

If you need to find the exact cause of a memory leak, I suggest you use a memory profiler such as XHProf.

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

+1
source share

Search for:

1) Cron Tasks

2) Queries using '*' and

3) Queries that use tables without INDEXES.

4) Special, long, non-optimized requests. For example, these are queries with a large number of subqueries.

5) Run these queries using the EXPLAIN statement and find out which tables should be optimized. Read here how to use the explanation: Using the explanation

You should install something like New Relic on your server / application, it has a free tier mode that can help you find long queries and processes.

Now I assume that there is no important processing that you do, and did not tell us about, for example, long image processing lists.

This can kill the beast of the car if it is not optimized.

Remember that long loops can also be a memory leak. If this is your case, you can experiment with switching from foreach loops to loops, for example.

+1
source share

All Articles