PHP Optimization

From Server rental store
Revision as of 18:13, 15 April 2025 by Admin (talk | contribs) (Automated server configuration article)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1. PHP Optimization for MediaWiki 1.40

This article details techniques for optimizing PHP performance on a MediaWiki 1.40 installation. Proper PHP configuration is crucial for a responsive and efficient wiki, especially under heavy load. This guide assumes a basic understanding of server administration and PHP.

Understanding PHP's Impact on MediaWiki

MediaWiki is a PHP-based application. The majority of its processing is done by the PHP interpreter. Therefore, optimizing PHP significantly impacts the wiki's overall performance. Key areas to focus on include memory allocation, opcode caching, and process management. Slow PHP execution leads to increased page load times, database bottlenecks, and a degraded user experience. Regularly monitoring Server Performance is recommended.

PHP Configuration File (php.ini)

The primary method for controlling PHP's behavior is through the `php.ini` file. The location of this file varies depending on your operating system and PHP installation method. Common locations include `/etc/php/7.4/cli/php.ini` (for command-line usage) and `/etc/php/7.4/apache2/php.ini` (for Apache web server integration). Always back up your `php.ini` file before making any changes. After modifications, restart your web server (e.g., Apache or Nginx) or PHP-FPM to apply the new settings. See PHP Documentation for more details.

Recommended php.ini Settings

The following settings are generally beneficial for MediaWiki performance. Values may need adjustments based on your server's resources.

Setting Recommended Value Description
`memory_limit` `256M` or higher Maximum amount of memory a script may consume. Increase if you encounter memory exhaustion errors.
`max_execution_time` `60` Maximum time a script is allowed to run, in seconds.
`upload_max_filesize` `100M` Maximum allowed size for uploaded files.
`post_max_size` `100M` Maximum size of POST data accepted.
`max_input_vars` `3000` Maximum number of input variables accepted.
`error_reporting` `E_ALL & ~E_NOTICE & ~E_DEPRECATED` Controls the level of error reporting.
`display_errors` `Off` (in production) Whether to display errors to the browser. Disable in production for security.

Opcode Caching

Opcode caching significantly improves PHP performance by storing compiled PHP code in memory. This avoids the need to recompile the code on every request. Opcode Cache is essential.

Popular Opcode Caches

Opcode Cache Description Installation (Example - Debian/Ubuntu)
OPcache (PHP 5.5+) Built-in opcode cache. Generally the easiest to configure. Typically enabled by default. Check `php.ini` for `opcache.enable=1`.
APCu (Alternative PHP Cache, user-space) A user-space opcode cache. Useful for shared hosting environments. `sudo apt-get install php-apcu`
Zend OPcache Another popular, high-performance opcode cache. Often bundled with PHP distributions.

To enable OPcache, ensure the following settings are present in your `php.ini`:

```ini [opcache] opcache.enable=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4096 opcache.revalidate_freq=60 ```

Adjust the `opcache.memory_consumption` value based on your wiki's size and traffic.

Process Management with PHP-FPM

For high-traffic wikis, using PHP-FPM (FastCGI Process Manager) is highly recommended. PHP-FPM manages a pool of PHP processes, which improves performance and stability compared to traditional mod_php. See the PHP-FPM Configuration page for details.

PHP-FPM Pool Configuration

Configure PHP-FPM pools to dedicate resources to your MediaWiki installation. A sample pool configuration (`/etc/php/7.4/fpm/pool.d/mediawiki.conf`):

Parameter Value
`user` `www-data` The user that PHP-FPM processes will run as.
`group` `www-data` The group that PHP-FPM processes will run as.
`listen` `/run/php/php7.4-fpm-mediawiki.sock` The Unix socket that PHP-FPM will listen on.
`listen.owner` `www-data` The owner of the Unix socket.
`listen.group` `www-data` The group of the Unix socket.
`pm` `dynamic` Process manager type.
`pm.max_children` `5` Maximum number of child processes.
`pm.start_servers` `2` Number of processes started on startup.
`pm.min_spare_servers` `1` Minimum number of idle processes.
`pm.max_spare_servers` `3` Maximum number of idle processes.
`php_admin_value[error_log]` `/var/log/mediawiki-php-fpm.log` Error log file.

Adjust the `pm.max_children`, `pm.start_servers`, `pm.min_spare_servers`, and `pm.max_spare_servers` values based on your server's resources and traffic patterns. Monitor PHP-FPM Statistics to optimize these settings.

Additional Optimization Techniques

  • **Database Caching:** Utilize Caching Systems like Memcached or Redis to cache frequently accessed database queries.
  • **Regular Updates:** Keep PHP and MediaWiki up-to-date with the latest security patches and performance improvements.
  • **Code Optimization:** Review and optimize custom extensions or skins for performance bottlenecks.
  • **HTTP Acceleration:** Implement a reverse proxy like Varnish or Nginx caching to reduce load on the PHP server. See Reverse Proxy Configuration.
  • **Consider a Content Delivery Network (CDN):** For static assets, a CDN can drastically improve load times for geographically dispersed users.


Special:MyPreferences Help:Contents Manual:Configuration Manual:Performance Manual:Upgrading Extension:CacheHitmen Help:FAQ Server Configuration Database Configuration Software Requirements


Intel-Based Server Configurations

Configuration Specifications Benchmark
Core i7-6700K/7700 Server 64 GB DDR4, NVMe SSD 2 x 512 GB CPU Benchmark: 8046
Core i7-8700 Server 64 GB DDR4, NVMe SSD 2x1 TB CPU Benchmark: 13124
Core i9-9900K Server 128 GB DDR4, NVMe SSD 2 x 1 TB CPU Benchmark: 49969
Core i9-13900 Server (64GB) 64 GB RAM, 2x2 TB NVMe SSD
Core i9-13900 Server (128GB) 128 GB RAM, 2x2 TB NVMe SSD
Core i5-13500 Server (64GB) 64 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Server (128GB) 128 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Workstation 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000

AMD-Based Server Configurations

Configuration Specifications Benchmark
Ryzen 5 3600 Server 64 GB RAM, 2x480 GB NVMe CPU Benchmark: 17849
Ryzen 7 7700 Server 64 GB DDR5 RAM, 2x1 TB NVMe CPU Benchmark: 35224
Ryzen 9 5950X Server 128 GB RAM, 2x4 TB NVMe CPU Benchmark: 46045
Ryzen 9 7950X Server 128 GB DDR5 ECC, 2x2 TB NVMe CPU Benchmark: 63561
EPYC 7502P Server (128GB/1TB) 128 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/2TB) 128 GB RAM, 2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/4TB) 128 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/1TB) 256 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/4TB) 256 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 9454P Server 256 GB RAM, 2x2 TB NVMe

Order Your Dedicated Server

Configure and order your ideal server configuration

Need Assistance?

⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️