Using comet with PHP?

后端 未结 11 1542
星月不相逢
星月不相逢 2020-11-22 03:09

I was thinking of implementing real time chat using a PHP backend, but I ran across this comment on a site discussing comet:

My understanding is that

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 03:50

    You may also try https://github.com/reactphp/react

    React is a low-level library for event-driven programming in PHP. At its core is an event loop, on top of which it provides low-level utilities, such as: Streams abstraction, async dns resolver, network client/server, http client/server, interaction with processes. Third-party libraries can use these components to create async network clients/servers and more.

    The event loop is based on the reactor pattern (hence the name) and strongly inspired by libraries such as EventMachine (Ruby), Twisted (Python) and Node.js (V8).

    The introductory example shows a simple HTTP server listening on port 1337:

     'text/plain');
    
        $response->writeHead(200, $headers);
        $response->end($text);
    };
    
    $loop = React\EventLoop\Factory::create();
    $socket = new React\Socket\Server($loop);
    $http = new React\Http\Server($socket);
    
    $http->on('request', $app);
    
    $socket->listen(1337);
    $loop->run();
    

提交回复
热议问题