Preloader
Troubleshooting

Tutorial: How to Fix Memory Leaks in Xtream UI

Stop your server from crashing by optimizing PHP-FPM, FFmpeg, and Database processes.


Is it really a "Leak"?

Often, what looks like a memory leak in Xtream UI is actually process pools not recycling correctly or runaway FFmpeg jobs. This guide provides an end-to-end playbook to identify the culprit and apply stability fixes to the typical Xtream UI stack (NGINX + PHP-FPM + MariaDB).

1Step 1: Diagnose the Problem

Before changing settings, identify what is consuming your RAM. Run the following command to see the top memory consumers:

ps -eo pid,ppid,cmd,%mem,rss --sort=-rss | head -n 15

Common Culprits:

  • php-fpm: Process pools not recycling (Most Common).
  • ffmpeg: Stuck transcode jobs or too many concurrent streams.
  • mysqld: Database buffer pool configuration issues.

2Step 2: Fix PHP-FPM (The #1 Fix)

PHP-FPM processes can balloon in memory usage over time. The most effective fix is to force them to recycle periodically and use "ondemand" mode so they don't sit idle consuming RAM.

Edit your PHP pool config (usually found at /etc/php/7.x/fpm/pool.d/www.conf):

nano /etc/php/7.2/fpm/pool.d/www.conf

Find and modify these directives:

pm = ondemand pm.max_children = 50 ; Adjust based on your RAM (see Step 3) pm.process_idle_timeout = 10s pm.max_requests = 200

Why this works: pm.max_requests = 200 kills the worker after 200 requests, freeing any leaked memory. ondemand ensures workers only exist when there is traffic.

3Step 3: Calculating Concurrency

Setting pm.max_children too high allows PHP to eat all your RAM. A safe rule of thumb is to allow PHP to use about 70% of your available RAM.

Formula: (Total RAM * 0.7) / Average PHP Process Size

Example: If you have 8GB RAM and an average PHP process takes 60MB:

(8192MB * 0.7) / 60MB = ~95 max_children

4Step 4: Emergency Restart Safety Valve

For unstable pools, you can configure PHP-FPM to self-restart if too many child processes fail. Edit the main config file:

nano /etc/php/7.2/fpm/php-fpm.conf

Add or uncomment these lines:

emergency_restart_threshold = 10 emergency_restart_interval = 1m process_control_timeout = 10s

Restart PHP-FPM to apply changes: service php7.2-fpm restart

5Step 5: Database & FFmpeg

FFmpeg: Check for "ghost" processes that are running but not streaming. You can count running jobs with:

pgrep -a ffmpeg | wc -l

MariaDB/MySQL: If MySQL is the culprit, check your innodb_buffer_pool_size in /etc/mysql/my.cnf. It should generally be set to 50-70% of total RAM on a dedicated database server, but much less if running on the same server as streams.