Swoole-src: Handling URL in swoole

Created on 10 Nov 2018  ·  3Comments  ·  Source: swoole/swoole-src

The documentation only mention handling url from http://localhost

Using this code:

$http = new swoole_http_server("127.0.0.1", 9501);
$http->on('request', function ($request, $response) {
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->start();

How could swoole handle a different url. Suppose: http://localhost/otherpage

question

All 3 comments

You can start with some inspectation to check it out

var_dump($request)

Try the same for $response and $http in your case to get an overview :)

@jobs-git have you some success? :blush:

$http->on('request', function ($req, $resp) {
    $uri = $req->server['request_uri'];
    if ($uri == '/favicon.ico') {
        $req->status(404);
        $req->end();
    }
    elseif ($uri == '/chunk') {
        chunk($req, $resp);
    } else {
        no_chunk($req, $resp);
    }
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreybolonin picture andreybolonin  ·  4Comments

lotarbo picture lotarbo  ·  4Comments

pthreat picture pthreat  ·  3Comments

onanying picture onanying  ·  3Comments

AndyChanCode picture AndyChanCode  ·  3Comments