<?php
require __DIR__ . '/vendor/autoload.php';
error_reporting(-1);
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Server;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Socket;
use Psr\Log\NullLogger;
// Run this script, then visit http://localhost:1337/ in your browser.
Amp\Loop::run(function () {
$sockets = [
Socket\listen("0.0.0.0:1338"),
];
$server = new Server($sockets, new CallableRequestHandler(function (Request $request) {
return new Response(Status::OK, [
], "Hello World!");
}), new NullLogger());
yield $server->start();
});
swoole.php
<?php
$http = new swoole_http_server("127.0.0.1", 9501);
$http->on("start", function ($server) {
echo "Swoole http server is started at http://127.0.0.1:9501\n";
});
$http->on("request", function ($request, $response) {
$response->end("Hello World");
});
$http->start();
0. Run some SOMECOMMAND
1. ctrl+z to stop (pause) the program and get back to the shell
2. bg to run it in the background
3. disown -h so that the process isn’t killed when the terminal closes
4. Type exit to get out of the shell because now your good to go as the operation will run in the background in it own process so its not tied to a shell