Replies: 1 comment 2 replies
-
Now I am creating a http server in a similar way in SWOOLE_BASE mode, it is important for me to understand if I am implementing this code correctly? <?php
declare(strict_types=1);
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;
$server = new Server('0.0.0.0', 9000, SWOOLE_BASE, SWOOLE_SOCK_TCP);
$server->set([
'http_parse_post' => true,
'http_parse_files' => false,
'http_parse_cookie' => false,
'http_compression' => true,
'http_compression_level' => 1,
'compression_min_length' => 128,
]);
$server->on('start', function (Server $server) {
echo "PHP Http server running at http://$server->host:$server->port" . PHP_EOL;
});
$server->on('request', function (Request $request, Response $response) {
$response->header('Content-Type', 'application/json');
$response->status(200);
$response->end(
json_encode([
'message' => 'Hello, world!',
]),
);
});
$server->start(); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone, please tell me how to create an http server correctly.
What do I need to know to create a http server?
What is the best mode to run the http server in?
What events are available for the http server?
What settings are required for the http server to work correctly?
What is the difference between SWOOLE_BASE and SWOOLE_PROCESS?
Please share your experience, thanks in advance :)
I know that there is documentation, but because of the language barrier, it's hard for me to understand it.
Beta Was this translation helpful? Give feedback.
All reactions