PHP Accelerators for 1C-Bitrix: Configuring OPcache, JIT, and APCu

PHP Accelerators for 1C-Bitrix: Configuring OPcache, JIT, and APCu You enabled OPcache, upgraded to the latest PHP version, but pages still load slowly? A typical scenario: bytecode cache is active, but Bitrix still spends too much time thinking on each request. We encounter this on nearly every

Our competencies:

Frequently Asked Questions

PHP Accelerators for 1C-Bitrix: Configuring OPcache, JIT, and APCu

You enabled OPcache, upgraded to the latest PHP version, but pages still load slowly? A typical scenario: bytecode cache is active, but Bitrix still spends too much time thinking on each request. We encounter this on nearly every other project during performance audits. The issue is often misaligned configuration of three mechanisms: OPcache (bytecode cache), JIT compilation (PHP 8.0+), and APCu (in-memory data cache). The right combination yields a 20–40% boost in PHP processing speed—sometimes even more if the CPU is the bottleneck.

Why OPcache Alone Isn't Enough

OPcache speeds up repeated script execution—parsing and compilation happen only once. But Bitrix is a heavy application with thousands of files and complex logic. Even with OPcache, each request spends time initializing the kernel, loading modules, and connecting to the database. JIT compilation takes the next step: it converts hot bytecode into machine code. The theoretical improvement is up to 5x, but in practice, for I/O-bound web pages (database, disk), JIT delivers 5–15%. However, on pages with intensive computations (e.g., report generation, cart processing), the effect is noticeable.

How to Configure JIT Properly

We recommend the following configuration in php.ini:

[opcache] opcache.enable = 1 opcache.memory_consumption = 192 opcache.jit = 1255 opcache.jit_buffer_size = 64M 

The 1255 value is not magic—it's a code indicating tracing mode and optimization level. For stability, use tracing:

opcache.jit = tracing opcache.jit_buffer_size = 32M 

Tracing is more effective for loops, but on short requests (typical for Bitrix) the gain is smaller. The mode should be selected based on the specific project's load profile.

Installing and Configuring APCu

APCu provides a key-value store in shared memory. Bitrix uses it through its own caching layer (Bitrix\Main\Data\ManagedCache). Install via PECL:

pecl install apcu echo "extension=apcu.so" > /etc/php.d/40-apcu.ini 

Configuration (in php.ini or /etc/php.d/40-apcu.ini):

[apcu] apc.enabled = 1 apc.shm_size = 128M apc.ttl = 3600 apc.user_ttl = 3600 apc.gc_ttl = 600 apc.slam_defense = 1 apc.enable_cli = 0 

apc.slam_defense = 1 protects against the dog-pile effect: when a cache entry expires, only one process regenerates it; others wait or use stale data.

Connecting APCu to Bitrix Caching

In the file /bitrix/php_interface/dbconn.php, add:

define("CACHED_b_file", 3600); define("CACHED_b_agent", 3610); define("CACHED_b_lang", 3600); define("CACHED_b_option", 3600); define("CACHED_b_iblock", 3600); define("BX_CACHE_TYPE", "apc"); define("BX_CACHE_SID", $_SERVER["DOCUMENT_ROOT"] . "/"); 

After that, Bitrix will store cache in APCu. Invalidation is tag-based—the system writes tags to the b_cache_tag table and checks them on each request.

Comparison of Caching Mechanisms

Mechanism Purpose Typical Gain Memory Consumption
OPcache Bytecode cache 30–50% (CPU) 128–192 MB
JIT Hot code compilation 5–15% 32–64 MB
APCu Data cache (query results) 20–40% (CPU) 128 MB

Tricky Part: Multiple Sites on the Same Server

APCu lives in the shared memory of the PHP-FPM process. Two sites in the same pool share one APCu space. To prevent one site's cache from overwriting the other's, use separate PHP-FPM pools and assign a unique BX_CACHE_SID including $_SERVER["DOCUMENT_ROOT"] (as in the example above).

What's Included in Turnkey Configuration

  • Audit of current PHP and server configuration
  • Determination of optimal OPcache, JIT, and APCu parameters based on load profile
  • Installation and configuration of extensions
  • Performance testing with ab or JMeter
  • Team training on monitoring basics
  • Written report with recommendations for further optimization

Common Configuration Mistakes

  • Forgetting to disable OPcache in development mode—resulting in "stale" code
  • Setting opcache.memory_consumption too small—cache eviction
  • Not verifying that APCu is available in PHP (apcu_enabled() returns false)
  • Using Swoole or FrankenPHP without code adaptation—leading to memory leaks and instability

Testing the Results

Measure before and after with the ab utility:

ab -n 1000 -c 10 http://site.ru/catalog/ | grep "Requests per second" 

Expected improvement on a typical catalog page: 20–40%. If there is no improvement, the bottleneck is likely the database, not PHP.

Our experience: over 50 Bitrix optimization projects with an average speedup of 30%. We guarantee transparent configuration and team training. Contact us for a preliminary assessment—we'll analyze your current configuration and propose a work plan.

Note: For deeper optimization, consider web server caching (nginx fastcgi cache), CDN, and queue setup for background tasks (Bitrix agents). More about caching in the official Bitrix developer documentation.

Accelerator Configuration Checklist
  • [ ] Check PHP version (>=8.0 for JIT)
  • [ ] Install OPcache (built-in) and APCu
  • [ ] Configure php.ini according to recommendations
  • [ ] Verify through phpinfo() that OPcache and APCu are active
  • [ ] Run load tests before and after