forked from php-runtime/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add response runner in frankenphp (php-runtime#177)
- Loading branch information
1 parent
2246529
commit 38bac35
Showing
6 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Runtime\FrankenPhpSymfony; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Runtime\RunnerInterface; | ||
|
||
/** | ||
* A response runner for FrankenPHP. | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
class ResponseRunner implements RunnerInterface | ||
{ | ||
public function __construct( | ||
private Response $response, | ||
private int $loopMax, | ||
) { | ||
} | ||
|
||
public function run(): int | ||
{ | ||
// Prevent worker script termination when a client connection is interrupted | ||
ignore_user_abort(true); | ||
|
||
$server = array_filter($_SERVER, static fn (string $key) => !str_starts_with($key, 'HTTP_'), ARRAY_FILTER_USE_KEY); | ||
$server['APP_RUNTIME_MODE'] = 'web=1&worker=1'; | ||
|
||
$handler = function () use ($server, &$sfRequest): void { | ||
// Merge the environment variables coming from DotEnv with the ones tied to the current request | ||
$_SERVER += $server; | ||
|
||
$sfRequest = Request::createFromGlobals(); | ||
$this->response->send(); | ||
}; | ||
|
||
$loops = 0; | ||
do { | ||
$ret = \frankenphp_handle_request($handler); | ||
|
||
gc_collect_cycles(); | ||
} while ($ret && (-1 === $this->loopMax || ++$loops < $this->loopMax)); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters