dennikolas
@dennikolas
PHP макака

Как задать порт Heroku?

Как задать определённый порт воркеру на пхп?

Воркер запускает сервак swoole:
$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();


Порт какой бы ни указывал - не пускает через браузер.
443 и 80 указывать нельзя - Permission denied.
  • Вопрос задан
  • 660 просмотров
Решения вопроса 1
dennikolas
@dennikolas Автор вопроса
PHP макака
Решил сам, был очень близко к решению.

Просто в procfile нужно было указать:
web: php web/server.php
Я же указывал:
worker: php web/server.php

Плюс в коде нужно прописать порт взятый из окружения, переменная PORT:
$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();
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы