amphp / http-server

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.

Home Page:https://amphp.org/http-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why direct sockets used instead of SocketServer ?

Ekstazi opened this issue · comments

$this->boundServers[$server->getAddress()->toString()] = $server->getResource();

$onAcceptable = \Closure::fromCallable([$this, 'onAcceptable']);

\stream_context_set_option($server, "ssl", "alpn_protocols", \implode(", ", $protocols));

if (!$socket = @\stream_socket_accept($server, 0)) {

SocketServer support tls and accept methods. So why http server use rar sockets instead of abstractions ?

This was afaik done for performance reasons, in particular all incoming client connections are (nearly) permanently alive and we just disable watching when our internal buffer limit gets reached.

It's in the end a lot of objects and enabling back and forth (if you consider ResourceInputStream->read() for example).
And this is in the hot path of the server...

p.s.: We technically could use the SocketServer API for accepting, but we'd definitely then have to unwrap the raw resource after accepting for performance. Also note that we have a common function for accepting from all bound sockets. With the socket server API you'd have essentially as many generators as server sockets…

It seems like all questions have been answered. If not, please respond with further questions, the issue can always be re-opened. 👍