Php stream_select如何工作?

public function __construct() {
    if (!$this->Listen()) {
        throw new Exception;
    }
     while (1) {
        $read = $this->master;
        $mod_fd = stream_select($read, $w = null, $e = null, 5, 00);
        if ($mod_fd === FALSE) {
            throw new Exception;
        }
        foreach ($read as $feed => $stream) {
            if ($stream === $this->master['main']) {
                $conn = stream_socket_accept($this->master['main']);
                $this->master[count($this->master)] = $conn;
            } else {
                $this->ReadStream($feed, $stream);
            }
        }
    }
}

private function Listen() {
    $socket = stream_socket_server("tcp://0.0.0.0:6001", $errno, $errstr);
    if ($errstr != '') {
        return false;
    }
    $this->master['main'] = $socket;
    return true;
}

My understanding is that stream_select will fill $read with the streams that have data available for reading.

My intention was to read each stream in $read one after the other but something really screwey is going on inside ReadStream where sometimes the data appears to be coming from a different stream than I expected.

Perhaps $read is being modified by stream_select before I got a chance to loop through them? But I thought that everyting in the process will happen asynchronously so now I'm totally confused

You are creating a socket, therefore you need to use socket_select, not stream_select. The later is for file streams.

You need to call socket_read to get any data from it.

The PHP manual has some create examples in the comment section.