Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\Server->handle(callable $callback): void
The main processing function for when a connection is received to the server. This callback handles server requests. Check the example on its usage and parameters.
None
The main processing function used for when successful connections are received.
You must set this function before starting the server.
When a connection is successful, when the callback is called to handle the request, the server will have already created a coroutine for you, no need to create one yourself.
<?php
$server = new OpenSwoole\Coroutine\Server('127.0.0.1', 8080);
$server->handle(function(OpenSwoole\Coroutine\Server\Connection $connection)
{
while(true)
{
$data = $connection->recv();
}
});
...
This callback is given a OpenSwoole\Coroutine\Server\Connection
object to allow you to process the request and access information about it. You can use $connection->exportSocket()
to get the underlying UnixSocket object if you need to.