Answer the question
In order to leave comments, you need to log in
How to set the Heroku port?
How to set a specific port for a worker in php?
The worker starts the swoole server:
$http = new Server('0.0.0.0', '8443', SWOOLE_BASE);
$http->on('start', function (Server $server) use ($container) {
$logger = $container->get(Logger::class);
$config = $container->get('config');
$logger->info('Swoole http server is started at ' . $config['app']['url'] . ', port :8443');
});
$http->on('request', function (Request $request, Response $response) use ($container) {
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
});
$http->start();
Answer the question
In order to leave comments, you need to log in
I decided on my own, I was very close to the solution.
It was just necessary to specify in the procfile:
web: php web/server.php
I indicated:
worker: php web/server.php
Plus, in the code you need to specify the port taken from the environment, the PORT variable:
$port = getenv('PORT');
$http = new Server('0.0.0.0', $port, SWOOLE_BASE);
$http->on('start', function (Server $server) use ($container) {
$logger = $container->get(Logger::class);
$config = $container->get('config');
$logger->info('Swoole http server is started at ' . $config['app']['url'] . ', port :' . $port);
});
$http->on('request', function (Request $request, Response $response) use ($container) {
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
});
$http->start();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question