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:
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):
Find and modify these directives:
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:
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:
Add or uncomment these lines:
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:
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.
