• I added my recent work with PHP preprocessors to make things cleaner, and made the first couple of endpoints: $host = new 8080); $host-use($router = = = process = process is from config.pre I decided to use Aerys for the HTTP and Web Socket portions of the application.
  • Finally I added pre/short-closures, both to handle the custom syntax in config.pre and the short closures I planned on using after… Then I set about creating routes files: use Aerys\Router; use App\Action\HomeAction; return (Router $router) = { $router-route( “GET”, “/”, new HomeAction ); }; This is from routes/web.
  • Finally, I created two (similar) actions: namespace App\Action; use Aerys\Request; use Aerys\Response; class HomeAction { public function __invoke(Request $request, Response $response) { $response-end(“hello world”); } } This is from final touch was to add shortcut scripts, to launch dev and prod versions of the Aerys server: “scripts”: { “dev”: “vendor/bin/aerys -d -c loader.php”, “prod”: “vendor/bin/aerys -c loader.php” }, “config”: { “process-timeout”: 0 }, This is from composer.json With all of this done, I could spin up a new server, and visit just by typing: composer dev Setting Up The Front-end “Ok, now that I’ve got the PHP side of things relatively stable; how am I going to build the ReactJS files?
  • I noticed Mix liked to create a manifest file, so I made a helper function to query it: use Amp\Coroutine; function mix($path) { $generator = () = { $manifest = yield $manifest = json_decode($manifest, true); if (isset($manifest[$path])) { return $manifest[$path]; } throw new Exception(“{$path} not found”); }; return new is from helpers.pre Aerys knew how to handle promises when they came in the form of $val = yield $promise, so I used Amp’s Promise implementation.
  • I found this relatively straightforward, with a new class: namespace App\Socket; use Aerys\Request; use Aerys\Response; use Aerys\Websocket; use Aerys\Websocket\Endpoint; use GameSocket implements Websocket { private $endpoint; private $connections = []; public function onStart(Endpoint $endpoint) { $this-endpoint = $endpoint; } public function onHandshake(Request $request, Response $response) { $origin = if ($origin !

Read more


@sitepointdotcom: “Game Development with ReactJS and PHP: How Compatible Are They?:” open tweet »

Show your support

Clapping shows how much you appreciated ReactJS News’s story.