Optimization of TTFB (Time to First Byte) 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Optimizing TTFB (Time to First Byte) for 1C-Bitrix

TTFB is the time from sending an HTTP request to receiving the first byte of response. It's pure server time: DNS, TCP connection, SSL handshake plus page generation time. Google PageSpeed considers good TTFB < 200 ms. Standard Bitrix site without optimization has 800 ms – 3 seconds.

What TTFB Consists of in Bitrix

Typical breakdown on a heavy site:

Stage Time What Affects
DNS + TCP + SSL 20–100 ms Hosting, CDN, geolocation
PHP initialization + Bitrix 50–150 ms OPcache, autoload
Kernel load, modules, prologue 30–100 ms Number of modules, include in init.php
SQL queries to database 100–2000 ms Indexes, cache, query optimization
Component execution 50–500 ms Component cache, template complexity
PHP buffer, obfuscator 10–50 ms Output settings

On most projects, 60–80% of TTFB is SQL queries. Start with them.

OPcache — Basic PHP Optimization

PHP without OPcache compiles every file on each request. Bitrix when fully loaded includes 200–500 PHP files. OPcache caches compiled bytecode:

[opcache]
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 20000
opcache.validate_timestamps = 0   ; on production — don't check file changes
opcache.revalidate_freq = 0
opcache.fast_shutdown = 1
opcache.enable_cli = 0

validate_timestamps = 0 is critical for speed. OPcache then doesn't see file changes without reset. After deployment, clear cache: opcache_reset() or cachetool utility. Without this setting, OPcache does stat() for each file per request — hundreds of syscalls.

max_accelerated_files = 20000 — Bitrix with typical modules has 5000–15000 PHP files. If limit is smaller — some files aren't cached. Check: opcache_get_status()['opcache_statistics']['num_cached_scripts'].

Page and Component Cache

Most effective way to lower TTFB is not generate page at all, return cached HTML. Bitrix can cache at several levels:

Component cache ($cache_time in .parameters.php). Standard bitrix:catalog.section component is cached for one hour. With proper configuration, repeat request has 5–20 SQL queries instead of 100–300.

Managed cache / Composite. Composite Site technology in Bitrix divides page into cacheable and dynamic parts. Cacheable part (main column, menu, header) is served immediately, dynamic part (cart, notification count) loads via AJAX. With proper setup, main HTML TTFB drops to 50–100 ms.

Enable Composite: Settings → Performance → Composite Site. Components are marked as dynamic via CBitrixComponent::setDynamicMode() or bitrix:catalog.top.menu with DYNAMIC = Y parameter.

HTML cache nginx. Fastest option — nginx serves static HTML without running PHP. Implemented via nginx FastCGI cache or Varnish in front of Bitrix. Requires proper invalidation on content update.

Optimizing Prologue and init.php

Every Bitrix request executes /bitrix/php_interface/init.php. If heavy classes are loaded, SQL queries made, or third-party libraries included — this adds to every request.

Check /bitrix/php_interface/init.php:

  • no include of files needed only in specific controllers
  • no initialization of third-party SDKs (1C integration, payment systems) on every request
  • no SQL queries in OnPageStart event handlers

Lazy-loading via Loader::includeModule() — modules are included only where needed. Don't include entire module list in init.php globally.

Database: Connection and Queries

Time to establish MySQL connection is 1–5 ms for local connection. When database is on separate server — 5–20 ms for TCP connection. Persistent connections (MYSQL_PCONNECT) allow reusing connection between requests within PHP-FPM worker.

In /bitrix/php_interface/dbconn.php:

$DBPersistent = true;  // enable persistent connections

Persistent connections reduce overhead but increase open connections on MySQL server. max_connections in my.cnf must be greater than PHP-FPM workers × virtual hosts.

Measuring TTFB by Stage

Diagnostics tool — Bitrix performance panel (/bitrix/admin/perfmon_panel.php or icon in bottom right). Enable profiling and open page. Panel shows:

  • total execution time
  • SQL query time cumulative and per query
  • component execution time
  • cache file operations count

For external measurement — curl -o /dev/null -s -w "Time to first byte: %{time_starttransfer}s\n" https://yoursite.ru/. Make 3–5 measurements: first may be with cold cache.

Optimization Timeline

Task Time TTFB Reduction
OPcache configuration 0.5 day 100–300 ms
SQL optimization (indexes, cache) 3–5 days 200–1500 ms
Component cache tuning 1–2 days 100–500 ms
Enable Composite Site 2–3 days 300–800 ms
Switch to Redis cache 1 day 20–100 ms
Nginx FastCGI cache 2–3 days 200–600 ms

Realistic goal for e-commerce on Bitrix with comprehensive optimization: TTFB < 300 ms for cached pages, < 800 ms for dynamic (personal account, checkout).