Esempio n. 1
0
class EchoGen
{
    private $message = '';
    public function put($message)
    {
        $this->message = $message;
    }
    public function get()
    {
        return "The message is: " . $this->message;
    }
}
$selector = new MioSelector();
$streams = new MioStreamFactory();
echo "Creating server...";
$selector->register($streams->createServerStream('127.0.0.1:8888'), MioSelectionKey::OP_ACCEPT);
echo "DONE\n";
$i = 0;
while (true) {
    /**
     * Add socket streams five at a time otherwise the server
     * buffer gets filled up and fsockopen blocks
     */
    for ($j = 0; $j < 5 && $i < 100; $i++, $j++) {
        echo "Creating client " . ($i + 1) . "...";
        $selector->register($streams->createSocketStream('127.0.0.1', 8888), MioSelectionKey::OP_WRITE, new MessageGen());
        echo "DONE\n";
    }
    while (!($count = $selector->select())) {
        if ($count === false || $count === 0 && count($selector->selection_keys) == 1) {
            $selector->close();