Skip to content

Problems using fd with resource. #191

@Provoker

Description

@Provoker

When using fd and resource there is a chance to get the same $key in the ExtEventLoop::addReadStream() method and similar methods, which leads to serious problems reading, writing and responding to events of another connection.

Small example

$fp1 = fsockopen("php.net", 80, $errno, $errstr, 30);
$fp2 = fsockopen("php.net", 80, $errno, $errstr, 30);

// [fp1] Resource id: 4, fd: 3
printf("[fp1] Resource id: %d, fd: %d\n", (int)$fp1, EventUtil::getSocketFd($fp1));

// [fp2] Resource id: 5, fd: 4
printf("[fp2] Resource id: %d, fd: %d\n", (int)$fp2, EventUtil::getSocketFd($fp2));

// bool(true)
var_dump((int)$fp1 === (int)EventUtil::getSocketFd($fp2));

This example demonstrates that we get the same $key when using the $fp1 resource and the file descriptor from $fp2, despite the fact that these are different connections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions