Skip to content

Writing Your First Swoole PHP

dhtmldhtml Posts: 27

**Create a file called sample1.php

$server = new Swoole\HTTP\Server("", 9501);

$server->on("start", function (Swoole\Http\Server $server) {
    echo "Swoole http server is started at\n";

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


Executing it:
Locate the file in your CLI and do the following:

$ php sample1.php

This will spin up a server and you will see something like:

$ swoole % php sample1.php

Swoole http server is started at

You can then copy and run that in your browser, you should see:

Hello World

You can find out more about swoole php here -

Sign In or Register to comment.