Skip to content

Stdlib: fsockopen() — procedural TCP wrapper missing while stream_socket_client partial (#3202) #8954

Description

@PurHur

Category

stdlib | runtime

Problem

Zend exposes both fsockopen($hostname, $port, …) and stream_socket_client('tcp://…'). This compiler registers stream_socket_client() (via VmStreamSocketNative) and pfsockopen(), but fsockopen() itself is not registeredfunction_exists('fsockopen') is false.

Legacy apps, PHPMailer, and health checks call fsockopen directly; parity requires the procedural wrapper.

php-src reference

Repro (failure today)

<?php
$errno = 0; $errstr = '';
$fp = @fsockopen('127.0.0.1', 9, $errno, $errstr, 1);
var_export([function_exists('fsockopen'), is_resource($fp), $errno, $errstr]);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "var_dump(function_exists(\"fsockopen\"), function_exists(\"stream_socket_client\"));"
php bin/vm.php repro_fsockopen.php
'

Verified 2026-06-16 harness: stream_socket_clientyes, fsockopenno.

Runtime function_exists('fsockopen') Connect port 9
Zend PHP 8.x true false + errno
bin/vm.php false fatal undefined function

Scope (this repo)

Path Work
ext/standard/fsockopen.php New builtin — build tcp://host:port and delegate to existing stream socket helper
ext/standard/Module.php Register
ext/standard/VmStreamSocketNative.php Shared transport (#8954 pure path)
Tests test/compliance/cases/stdlib/fsockopen_discard_port.phpt

Implement in ext/standard PHP; no new runtime/*.c socket table.

Done when

  • function_exists('fsockopen')true on VM
  • Repro: false resource + populated $errno/$errstr on unreachable port
  • $timeout float honored (subset matching Zend)
  • Enum hostname/port operands TypeError per php-src-strict (add PHPT if coerce bug found)
  • ./script/ci-fast.sh --filter fsockopen green

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 machinearea:webWeb / CGI / superglobalsenhancementNew 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