Category
stdlib | runtime
Status (expanded 2026-06-07 — implementation-ready)
Maintainer probe on master (Docker php-compiler:22.04-dev):
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php -r "var_dump(function_exists(\"pfsockopen\"), function_exists(\"fsockopen\"), function_exists(\"stream_socket_client\"));"'
# bool(false) bool(false) bool(true) — persistent opener missing; non-persistent fsockopen also absent
Workers should implement pfsockopen() on top of the existing stream_socket_client() / socket stream layer rather than new C in runtime/.
Problem
pfsockopen(string $hostname, int $port, …): resource|false opens a persistent socket stream reused across requests (CGI/FPM) or long-running scripts. Non-persistent fsockopen() is tracked in #3202; pfsockopen() is a separate php-src entry point with persistent handle caching in the stream layer.
function_exists('pfsockopen') is false under bin/vm.php.
php-src reference
Repro (failure today)
<?php
$errno = 0;
$errstr = '';
$fp = @pfsockopen('127.0.0.1', 9, $errno, $errstr, 1);
var_export(is_resource($fp));
echo "\n";
if (is_resource($fp)) {
fclose($fp);
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "var_dump(function_exists(\"pfsockopen\"));"
php bin/vm.php repro.php
'
| Runtime |
Result |
| Zend |
function_exists → true; stream resource or false + populated $errno/$errstr |
| This compiler VM |
undefined function fatal |
Scope (this repo)
| Module |
Path |
Notes |
| Persistent registry |
lib/VM/StreamRegistry.php or extend stream layer |
process-lifetime map host:port → handle |
| Builtin |
ext/standard/pfsockopen.php |
delegate connect to shared socket helper |
| Shared TCP |
reuse #3202 / stream_socket_client() internals |
do not fork separate connect code |
| Registration |
ext/standard/Module.php |
|
| JIT/AOT |
VM-first v1; document deferral in matrix |
|
| Tests |
test/compliance/cases/stdlib/pfsockopen.phpt |
discard port 9 or loopback mock |
| php-in-php |
keep stream tables in PHP (#5343 stream registry migration) |
no phpc_stream.c growth |
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter pfsockopen'
Dependencies
Category
stdlib|runtimeStatus (expanded 2026-06-07 — implementation-ready)
Maintainer probe on
master(Dockerphp-compiler:22.04-dev):Workers should implement
pfsockopen()on top of the existingstream_socket_client()/ socket stream layer rather than new C inruntime/.Problem
pfsockopen(string $hostname, int $port, …): resource|falseopens a persistent socket stream reused across requests (CGI/FPM) or long-running scripts. Non-persistentfsockopen()is tracked in #3202;pfsockopen()is a separate php-src entry point with persistent handle caching in the stream layer.function_exists('pfsockopen')is false underbin/vm.php.php-src reference
ext/standard/fsock.c—PHP_FUNCTION(pfsockopen),php_network_connect_socket_to_hostwith persistent flagmain/streams/streams.c—php_stream_popen, persistent list keyed byproto://host:portRepro (failure today)
function_exists→ true; stream resource orfalse+ populated$errno/$errstrScope (this repo)
lib/VM/StreamRegistry.phpor extend stream layerhost:port→ handleext/standard/pfsockopen.phpstream_socket_client()internalsext/standard/Module.phptest/compliance/cases/stdlib/pfsockopen.phptphpc_stream.cgrowthDone when
function_exists('pfsockopen')true on VMfalsewith$errno/$errstrlike Zendfclose()(Zend subset)./script/ci-fast.sh --filter pfsockopengreendocs/capabilities.mdrow addedVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter pfsockopen'Dependencies
fsockopen()base (shared connect path)