Skip to content

Stdlib: socket_create_pair() — Unix socket pair API missing (ext/sockets/sockets.c) #6563

Closed

Description

@PurHur

Category

stdlib

Problem

socket_create_pair() (ext/sockets) creates two connected socket endpoints for IPC. Distinct from stream_socket_pair() (#3437 / closed #4996) which returns stream resources — socket_create_pair() fills a by-ref array with Socket objects (PHP 8+).

This compiler: function_exists('socket_create_pair') → false.

php-src reference

Repro

<?php
var_export(function_exists('socket_create_pair'));
echo "\n";
$pair = [];
$ok = socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $pair);
var_export($ok);
echo "\n";
if ($ok) {
    socket_write($pair[0], "hi", 2);
    echo socket_read($pair[1], 2), "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
Runtime Output
Zend PHP 8.x true + hi
This compiler false then undefined function

Scope (this repo)

Piece Path / notes
ext module ext/sockets/ (phase 2 of #3399) — register after socket_create baseline
VM Socket class or resource + socket_write/socket_read on pair endpoints
Tests test/compliance/cases/stdlib/socket_create_pair.phpt (skip on hosts without AF_UNIX)
Matrix script/capability-matrix.php

Implement in ext/ + VM — no permanent logic in runtime/*.c beyond thin POSIX socketpair() ABI if unavoidable.

Done when

  • Repro: socket_create_pair() returns true, array of two usable sockets, round-trip "hi"
  • Wrong $domain/$type/$protocol → false + socket_last_error() like Zend
  • ./script/ci-fast.sh --filter socket_create_pair green on VM

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 6, 2026
  2. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (after #3366/#6490): socket_create_pair (#6563)

  3. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    Handoff (advanced stdlib batch after #3366 + #6490): blocked for a clean single-issue PR.

    socket_create_pair() repro needs endpoints that socket_write/socket_read accept. Today:

    • stream_socket_pair + socket_import_stream exist
    • socket_create / socket_write / socket_read / socket_close are not registered (function_exists → false)

    Phase-1 options for next run:

    1. Implement socket_create_pair via stream_socket_pair + socket_import_stream, and thin socket_write/socket_read on imported Socket objects (enough for the issue repro), or
    2. Land #3399 socket_create baseline first, then pair API.

    Not starting a half-wired pair stub this run — avoids green registration with red socket_write on the same issue.

  4. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #4387, #6138, #6563)

    Queued after #4387 and #6138. function_exists(socket_create_pair) is false on master.

  5. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — still queued after #4387 (#6138 merged via #19327).

  6. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — starting #6563 after #4387 merged (#19328) and #6138 (#19327).

  7. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    Merged via PR for #6563.

    Shipped: socket_create_pair() via SocketsLibcThinAbi::socketpair + owned Socket FDs; by-ref pair array.

    Verification:

    php bin/vm.php test/repro/issue_6563_socket_create_pair.php
    # true / true / hi
    php -d memory_limit=1536M vendor/bin/phpunit --filter socket_create_pair
    # OK
    
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