High Performance

Tuning realpath_cache_size for 32GB RAM

Leverage high RAM to eliminate PHP file path resolution overhead and achieve sub-200ms TTFB on complex frameworks.

Target
32GB+ RAM Servers
PHP Versions
5.6 - 8.1+
50-70%
Faster File Includes
200-400ms
TTFB Reduction
0.1% RAM
Memory Usage
32GB RAM Allocation

Visualizing optimal realpath_cache allocation on high-memory servers:

4KB
32MB
31.97GB
Default (Wasteful)
realpath_cache
System & Apps
RAM Allocation Insight

What is Realpath Cache?

Every time PHP includes a file (via require, include, or require_once), it must resolve the relative path to an absolute path on the disk. For complex frameworks like WordPressWordPress 6.0+ can include 150+ files per page load, causing repeated path resolution or MagentoMagento 2 can include 500+ files, making realpath cache critical for performance, this can involve hundreds of file lookups per request.

How It Works

By caching these resolved paths in RAM, PHP avoids hitting the file system repeatedly. This eliminates disk I/O overhead and significantly lowers Time to First Byte (TTFB) for every request.

PHP 8.1
PHP 7.2
PHP 5.6
PHP 8.1 Configuration

Check current realpath_cache settings for PHP 8.1:

Terminal
# For PHP 8.1 (Remi repository)
php81 -i | grep realpath_cache

# Or check via phpinfo()
php81 -r "phpinfo();" | grep -A2 -B2 realpath
Default location: /etc/opt/remi/php81/php.ini
PHP 7.2 Configuration

Check current realpath_cache settings for PHP 7.2:

Terminal
# For PHP 7.2 (Software Collections)
/opt/rh/rh-php72/root/usr/bin/php -i | grep realpath_cache

# Check active configuration
scl enable rh-php72 "php -i | grep realpath"
Default location: /etc/opt/rh/rh-php72/php.ini
PHP 5.6 Configuration

Check current realpath_cache settings for PHP 5.6:

Terminal
# For PHP 5.6
php56 -i | grep realpath_cache

# Or check the specific php.ini
php56 --ini | grep Loaded
Why 32GB RAM Matters

The default PHP limit is often 16K or 4096K. On a server with 32GB of RAM, we can comfortably increase this to 32M or more, ensuring the entire application path structure stays in memory while using less than 0.1% of available RAM.

Update php.ini Configuration

Edit your php.ini file and update the following directives for optimal 32GB server performance:

php.ini Configuration
; ============================================
; REALPATH CACHE OPTIMIZATION FOR 32GB RAM
; ============================================
; Increase size to 32MB (from default 16K/4MB)
; This uses only 0.1% of 32GB RAM
realpath_cache_size = 32M

; Increase TTL to 10 minutes (600 seconds)
; Files rarely move on production servers
realpath_cache_ttl = 600

; Optional: Enable for CLI as well (for cron jobs)
; realpath_cache_size_cli = 16M

; Optional: Monitor cache hits (development only)
; realpath_cache_debug = Off

Apply Configuration Changes

After updating php.ini, restart your PHP-FPM services. Since you're running multiple PHP versions, restart each one:

Terminal Commands
# Restart PHP 8.1 FPM
systemctl restart php81-php-fpm

# Restart PHP 7.2 FPM
systemctl restart rh-php72-php-fpm

# Verify services are running
systemctl status php81-php-fpm --no-pager -l
systemctl status rh-php72-php-fpm --no-pager -l

# Optional: Check PHP version to confirm changes
php81 -r "echo ini_get('realpath_cache_size');"

Monitoring & Verification

Monitor realpath cache usage to ensure optimal performance:

Monitoring Script
<?php
// realpath_cache_info.php - Place in web root
header('Content-Type: text/plain');

$cache_info = realpath_cache_getinfo();
$cache_size = realpath_cache_size();
$cache_ttl = ini_get('realpath_cache_ttl');

echo "=== Realpath Cache Status ===\n";
echo "Configured Size: " . ini_get('realpath_cache_size') . "\n";
echo "Current Usage: " . round($cache_size / 1024 / 1024, 2) . " MB\n";
echo "Cache TTL: " . $cache_ttl . " seconds\n";
echo "Entries in Cache: " . count($cache_info) . "\n";
echo "==============================\n";

// Show top 10 cached paths
$i = 0;
foreach ($cache_info as $path => $info) {
    if ($i++ >= 10) break;
    echo "\n" . $path . " (Age: " . $info['expires'] . "s)";
}
Monitoring Guidelines

If cache usage consistently exceeds 80% of your configured size during peak traffic, consider increasing realpath_cache_size. For 32GB servers with complex applications, 64MB is often optimal.

Performance Calculator
50 (Simple) 150 files 500 (Complex)
10 RPS 100 RPS 1000 RPS
Without Cache
450ms
With 32MB Cache
150ms
Estimated TTFB reduction per request

Need Custom PHP Tuning?

Our team specializes in enterprise PHP optimization for high-traffic Magento, WordPress, and Laravel installations.