Skip to content
PHP 8.6 Release: New Polling API, ZTS Boost, Performance Gains & Debugging Upgrades

PHP 8.6 Release: New Polling API, ZTS Boost, Performance Gains & Debugging Upgrades

PHP 8.6 introduces a new epoll-based polling API, cuts ZTS overhead by half, adds VM stack page caching for deep recursion, enables cross-request TLS session reuse, and delivers dozens of microbenchmark-verified performance improvements across string, array, and JSON functions, plus stricter session defaults and enhanced debugging with structured stream errors and JSON error locations.

21CTO
21CTO
21CTO

New Polling API

PHP 8.6 adds a scalable, epoll-based I/O polling API ( Io\Poll\Context, StreamPollHandle, Event) that overcomes previous stream_select() limitations. It leverages the best platform mechanism (epoll, kqueue, event ports, WSAPoll) and reduces manual state management. This benefits event-loop libraries like ReactPHP. Example:

use Io\Poll\Context;
use Io\Poll\Event;
use Io\Poll\StreamPollHandle;
use Time\Duration;

$context = new Context();
$stream = stream_socket_server('tcp://0.0.0.0:8080', $errno, $errstr);
stream_set_blocking($stream, false);
$handle = new StreamPollHandle($stream);
$context->add($handle, [Event::Read], ['type' => 'server']);
while (true) {
    $watchers = $context->wait(new Duration::fromSeconds(1));
    // …
}

ZTS Improvements: Overhead Halved vs NTS

Zend Thread Safety (ZTS) mode overhead is reduced by ~50% compared to the classic NTS mode (used by PHP-FPM). Main beneficiaries: FrankenPHP, Apache MPM event, Windows PHP builds. Marc Henderkes' optimizations may bring overhead near zero in the next version.

VM Stack Page Caching for Deep, Fragmented Call Stacks

Long-running scripts with deep call stacks previously triggered repeated allocation/freeing of stack pages when crossing thresholds. The fix retains freed pages in a free list for reuse. Ondřej Mirtes (PHPStan author) observed a drop from 537 seconds to 51 seconds when scanning a specific repository.

Cross-Request TLS Session Reuse

OpenSSL TLS sessions can now be cached via stream context ( session_data, session_new_cb) to resume handshakes, saving ~100 ms per reconnection. Example:

$previousSession = $_SESSION['tls_session'] ?? null;
$context = stream_context_create([
    'ssl' => [
        'peer_name' => 'api.example.com',
        'session_data' => $previousSession ? OpenSSLSession::import($previousSession) : null,
        'session_new_cb' => function ($stream, OpenSSLSession $session) {
            $_SESSION['tls_session'] = $session->export();
        }
    ]
]);
$fp = stream_socket_client('tls://api.example.com:443', context: $context);
// Second connection resumes, saving ~100ms handshake time

Microbenchmark-Verified Performance Improvements

The author created microbenchmarks (source on GitHub) for each change found in NEWS, UPGRADING, and git history, running on a neutral Linux machine. Key results: str_repeat($s, 1): 1836.1 ms → 36.7 ms (-98.0%) — returns input without copy (#23681) str_pad: 3890.8 ms → 98.3 ms (-97.5%) — single-char uses memset, longer pads copy two copies (#19272, #23661) array_reduce: 736.2 ms → 26.6 ms (-96.4%) — accumulator no longer copied per callback, O(n²)→O(n) (#21340) Collator::sortWithSortKeys(): 2695.1 ms → 139.1 ms (-94.8%) — buffer size scales with array, not fixed 2×1 MiB per call (#23504) array_intersect: 1139.4 ms → 61.7 ms (-94.6%) — hash-based matching instead of sorting all arrays (#23019) ZipArchive::addFromString(): 266.4 ms → 38.0 ms (-85.7%) — no content copy (#20497) mb_str_pad(): 634.3 ms → 113.2 ms (-82.2%) — pads by copying two copies (#23667) addcslashes: 414.1 ms → 85.5 ms (-79.4%) — octal escapes generated without sprintf (#23680) str_split(): 1491.0 ms → 416.4 ms (-72.1%) — optimized for length 1 (#20419) printf() with %s / %d: 1484.5 ms → 540.3 ms (-63.6%) — compiled to string interpolation inside functions (#19658) array_sum() / array_product() integer fast path: 819.4 ms → 356.7 ms (-56.5%) (#21787) foo(...) first-class callable caching: 1637.5 ms → 833.2 ms (-49.1%) (#19863) array_unshift packed-array fast path: 776.6 ms → 399.2 ms (-48.6%) (#20353)

Stateless closure ( static fn) caching: 880.9 ms → 487.2 ms (-44.7%) (RFC) pathinfo() with single PATHINFO_* flag skips unrequested components: 1028.3 ms → 644.7 ms (-37.3%) (#23726)

Single-element array sort skips unpacking/comparator: 982.1 ms → 636.4 ms (-35.2%) (#23550)

Asymmetric visibility ( private(set) / protected(set)) checks cached for writes: 462.1 ms → 310.1 ms (-32.9%) (#22709) preg_replace_callback no longer copies $matches array: 514.1 ms → 416.2 ms (-19.0%) (#21340) intval('0b…', 2) avoids string copy to strip prefix: 857.3 ms → 720.1 ms (-16.0%) (0af87e970) DOMText::splitText() faster, less memory: 321.1 ms → 271.0 ms (-15.6%) (#20371) array_fill_keys() optimized: 614.2 ms → 537.3 ms (-12.5%) (#20347) new self(...) with known constructor: 475.0 ms → 432.9 ms (-8.9%) (#20259) Uri\Rfc3986\Uri getters skip re-normalization: 435.2 ms → 405.8 ms (-6.8%) (#21726) array_column key normalization moved out of loop: 446.4 ms → 418.7 ms (-6.2%) (#23786) array_map(foo(...), $a) compiled to foreach: 422.6 ms → 412.0 ms (-2.5%) (#20934) array_map multiple arrays avoids per-iteration allocation: 589.7 ms → 578.2 ms (-1.9%) (79adb01bf) array_walk reduced per-element callback overhead: 740.8 ms → 729.8 ms (-1.5%) (#20322) stream_copy_to_stream() file→socket uses sendfile(): 847.9 ms → 867.3 ms (+2.3%, no diff in this run) (#20399)

Deprecated is_* functions: is_integer, is_double, is_long — replace with is_int, is_float, is_int respectively.

TAILCALL VM Improvements

TAILCALL VM (used on macOS/clang builds) improved by Arnaud: Symfony +1%, bench.php +3.5%. PHP runs on five VM types: CALL, GOTO, SWITCH, HYBRID, TAILCALL, defining how the engine jumps between opcode handlers.

Runtime Environment Changes

Stricter session defaults: session.use_strict_mode=1, session.cookie_httponly=1, session.cookie_samesite=Lax — may affect apps using ext/session. session.save_path with N;/path (dirdepth) now cleans nested subdirectories during garbage collection; previously required custom cron. ini_get_all($details=true) now includes builtin_default_value per directive, enabling runtime config drift detection.

OPcache file cache and system ID calculation fixes.

Debugging Enhancements

Error Argument Display

New error_include_args INI flag (default off) includes function arguments in errors. Respects zend.exception_string_param_max_len and #[​SensitiveParameter]. Enable in development only to avoid leaking sensitive data.

JSON Error Location

json_last_error_msg()

and JsonException now return messages like Syntax error near location 2:10 (line 2, column 10), aiding large payload debugging. Initial slowdown on success path is now negligible.

Structured Stream Errors

New error_mode stream context option ( StreamErrorMode::Exception) makes stream APIs throw StreamException instead of emitting warnings, reducing reliance on @ operator. Example:

$context = stream_context_create([
    'stream' => ['error_mode' => StreamErrorMode::Exception]
]);
try {
    $stream = fopen('/nonexistent/file.txt', 'r', false, $context);
} catch (StreamException $e) {
    echo "Error: " . $e->getMessage() . "
";
    echo "Code: " . $e->getCode() . "
";
}

See Jakub Zelenka's "Stream Error Handling Improvements RFC" for details.

Other Debugging Improvements

stream_socket_get_crypto_status()

returns STREAM_CRYPTO_STATUS_WANT_READ / WANT_WRITE for non-blocking TLS flow control (#22193).

SOAP encoding errors now name the affected type instead of generic "encoding rule violation" (#22708).

cURL option validation errors include the option name.

Reflection and error logs no longer truncate class/function names at NUL bytes (important for anonymous classes). ReflectionProperty::isReadable() and isWritable() consider visibility, hooks, and readonly. ReflectionParameter::getDocComment() added. __debugInfo() magic method now allowed in enums.

The article notes this list will be updated as more PHP 8.6 features are covered.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

debuggingperformance benchmarksPHP 8.6polling APIsession defaultsTLS session reuseVM improvementsZTS
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.