Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Http\Response->redirect(string $url, int $httpStatusCode = 302): void
The new address/location to jump to
The redirection HTTP status code, 302 means it was temporary and 301 represents a permanent jump
Redirect a HTTP client to a new address/location. Set the redirect status code which indicates the type of jump, default is 302.
Calling this redirect method will automatically call $response->end('')
for you and will end the response.
<?php
$server->on('Request', function(Swoole/Server/Request $request, Swoole/Server/Response $response)
{
$response->redirect("https://openswoole.com/", 301);
});