Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Support tasks that manage their own webserver #33

Open
KorvinSzanto opened this issue May 3, 2019 · 2 comments
Open

Support tasks that manage their own webserver #33

KorvinSzanto opened this issue May 3, 2019 · 2 comments

Comments

@KorvinSzanto
Copy link

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)

@txase
Copy link
Member

txase commented May 3, 2019

@KorvinSzanto In your example with serverless.php, would you be providing serverless.php as the handler value? I'm trying to make sure I understand things correctly.

@KorvinSzanto
Copy link
Author

@txase the difference is in one case I'm starting the built in PHP service, in the new case I'm asking for I'd be starting a PHP daemon that handles HTTP in a way that's entirely independent of the build in PHP server

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants