0

I am new to swoole and I am successfully done hello world on y local machine. But when i push the code on the server it doesn't work. I changed the server url and port but nothing worked

I just want to display a Hello message on my URL when someone opens this. Please be polite with me because i am new to this. Thanks in advance

Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68
  • 1
    What does "not work" mean? Is there an error message you are getting? Did you check the logs? What have you tried so far to identify and solve the problems? Give us something to work with, otherwise all we can do is guess your problem. – Christoph Jun 30 '21 at 13:33

1 Answers1

1

You need to use ip or socket, not hostname

ini_set('display_error', 1);
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

global $serverurl;
global $port;
$serverurl = "0.0.0.0";
$port = "3200";
$server = new Swoole\HTTP\Server($serverurl, $port, true);

$server->on("start", function (Server $server) {
    global $serverurl;
    global $port;
    echo "Swoole http server is started at {$serverurl}:{$port}\n";
});

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();
tchap
  • 3,412
  • 3
  • 29
  • 46
Luffy
  • 101
  • 2