Skip to content

Stdlib: fsockopen() / stream_socket_client() — TCP/UDP sockets (streams parity) #3202

Description

@PurHur

Category

stdlib | runtime · php-src-strict · spec refresh 2026-06-18

Problem

Socket client parity is partial. VM registers fsockopen(), pfsockopen(), and stream_socket_client() (ext/standard/fsockopen.php, stream_socket_client.php, Module.php#8954 closed). Remaining gaps:

  1. errno / errstr strings — VM returns 'Connection failed' where Zend returns 'Connection refused' for ECONNREFUSED (errno 111).
  2. libc FFIVmStreamSocketNative still uses socket FFI; self-host wants pure PHP transport (php-in-php: VmStreamSocketNative — TCP/UDP connect without libc socket FFI (#1492, streamsfuncs.c) #8953).
  3. UDP / timeout / persistent socket edge cases — not fully guarded vs php-src streamsfuncs.c.

Blocks: #3384 persistent sockets, #3131 proc_open socket pipes, FastCGI upstream (#173).

php-src reference

Repro

Phase 1 — registration (GREEN)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export([function_exists(\"fsockopen\"), function_exists(\"stream_socket_client\"), function_exists(\"pfsockopen\")]);"'
# array(true, true, true)

Phase 2 — connect + errno (verified 2026-06-18)

<?php
$errno = 0;
$errstr = '';
$fp = @fsockopen('127.0.0.1', 9, $errno, $errstr, 1);
var_export([is_resource($fp), $errno, $errstr]);
echo "\n";
php repro_fsock.php
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro_fsock.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro_fsock.php'
Check Zend PHP 8.2 VM / JIT today
is_resource($fp) false false
$errno 111 111
$errstr 'Connection refused' 'Connection failed'
JIT compiles n/a works (no LogicException)

Phase 3 — successful TCP (when listener available)

# Optional: start listener on 127.0.0.1:9876, then:
php bin/vm.php -r '$fp=fsockopen("127.0.0.1",9876); var_dump(is_resource($fp)); fclose($fp);'

Scope (this repo)

Module Path
VM builtins ext/standard/fsockopen.php, stream_socket_client.php, VmStreamSocketNative.php
Transport Pure PHP socket path per #8953
JIT/AOT Verify parity with VM (JIT connect path exists)
Tests test/compliance/cases/stdlib/fsockopen_tcp.phpt — assert errno and errstr

Done when (php-src-strict)

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions