I built a package to make Flarum work with ReactPHP. This allows you to serve Flarum under custom PHP HTTP servers. Enjoy!
Installation
composer require ordinaryjellyfish/flarum-react
Usage
In your Flarum's index.php
file:
require '../vendor/autoload.php';
use OrdinaryJellyfish\FlarumReact\Server as FlarumServer;
use React\Promise\Promise;
$loop = React\EventLoop\Factory::create();
$server = new React\Http\Server(function ($request) {
return new Promise(function ($resolve) use ($request) {
$flarumServer = new FlarumServer(
$request,
Flarum\Foundation\Site::fromPaths([
'base' => __DIR__.'/..',
'public' => __DIR__.'/../public',
'storage' => __DIR__.'/../storage',
])
);
$flarumServer->listen();
$resolve($flarumServer->getResponse());
});
});
$socket = new React\Socket\Server(8080, $loop);
$server->listen($socket);
$loop->run();
Visit http://localhost:8080 and voila! The beauty of Flarum arises. Note that this example does not handle static file serving. I may implement a handler to make everything simpler.
To add static file serving, use a middleware such as reactphp-static (disclaimer: i made it 😛).
Links
This is one of the few times I've messed around with ReactPHP, so the code may be messy to other standards! This library is also in a very early stage so I do not guarantee stability. Enjoy!
PRs are most welcome if you'd like to help make it better <3