How do I listen to a UNIX domain socket in a single-process HTTP/Web socket server ? #5308
-
This is my simple HTTP server: $server = new \Swoole\HTTP\Server("127.0.0.1", 9501);
$server->set([
'backlog' => 128, // TCP backlog connection number
]);
// Triggered when new worker processes starts
$server->on("WorkerStart", function($server, $workerId)
{
echo "Worker Started: $workerId\n";
});
// Triggered when the HTTP Server starts, connections are accepted after this callback is executed
$server->on("Start", function($server)
{
echo "HTTP Server Started @ 127.0.0.1:8501\n";
});
// The main HTTP server request callback event, entry point for all incoming HTTP requests
$server->on('Request', function(Swoole\Server\Request $request, Swoole\Server\Response $response)
{
// Handle request from TCP
$response->header("Content-Type", "text/plain");
$response->end("Hello, TCP World!\n");
});
$server->on('message', function($server, $data) {
var_dump($data);
});
$server->on('receive', function($server, $data) {
var_dump(func_get_args());
});
// Triggered when the server is shutting down
$server->on("Shutdown", function($server)
{
echo "Server shutting down...\n";
});
// Triggered when worker processes are being stopped
$server->on("WorkerStop", function($server)
{
echo "Worker Stopped: $workerId\n";
});
$server->start(); I need for my server to listen to the UNIX domain socket /var/run/myserver.sock How can I change the code to support this also (in a single process) ? Thanks ! |
Beta Was this translation helpful? Give feedback.
Answered by
NathanFreeman
Apr 30, 2024
Replies: 1 comment 8 replies
-
$server = new \Swoole\HTTP\Server("127.0.0.1", 9501);
$server->addlistener("/var/run/myserv.sock", 0, SWOOLE_UNIX_STREAM); //UnixSocket Stream |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call the
$unixSocket->set([]);
method to override the settings of the main serversee https://wiki.swoole.com/en/#/server/port?…