Support tasks that manage their own webserver #33
Description
Take for example a react-http php server in a file like serverless.php
:
<?php
$loop = Factory::create();
$server = new StreamingServer(function ($request) use ($loop) {
try {
return new Response(200, [], 'Hello World!');
} catch (\Exception $e) {
echo 'ERROR: ' . $e->getMessage();
return new Response(500, []);
}
});
$socket = new ReactSocketServer('0.0.0.0:8000', $loop);
if ((bool) $cert = getenv('SSL_CERT')) {
$socket = new SecureServer($socket, $loop, [
'local_cert' => __DIR__ . '/../../' . $cert
]);
}
$this->socket = $socket;
$server->listen($socket);
$loop->run();
Running php serverless.php
will start a server on port 8000 that will happily respond to requests the same way to built in PHP server would.
In order to make this work today, I believe I'd need to fork this repository and update the bootstrap. It'd be nice if I could simply declare the relevant bit in my configuration
exec("PHP_INI_SCAN_DIR=/opt/etc/php-7.${phpMinorVersion}.d/:/var/task/php-7.${phpMinorVersion}.d/ php -S localhost:8000 -c /var/task/php.ini -d extension_dir=/opt/lib/php/7.${phpMinorVersion}/modules '$handler_filename'");
would just become exec("PHP_INI_SCAN_DIR=/opt/etc/php-7.${phpMinorVersion}.d/:/var/task/php-7.${phpMinorVersion}.d/ php -c /var/task/php.ini -d extension_dir=/opt/lib/php/7.${phpMinorVersion}/modules '$handler_filename'");
(we removed the -S localhost:8000
)