From 6d272ff894fa969e5a526caf6a91d60eda115c53 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 28 Apr 2025 19:57:56 -0100 Subject: feat(async): AsyncProcess Signed-off-by: Maxence Lange --- core/Controller/AsyncProcessController.php | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 core/Controller/AsyncProcessController.php (limited to 'core/Controller/AsyncProcessController.php') diff --git a/core/Controller/AsyncProcessController.php b/core/Controller/AsyncProcessController.php new file mode 100644 index 00000000000..f644e3a7851 --- /dev/null +++ b/core/Controller/AsyncProcessController.php @@ -0,0 +1,77 @@ + ProcessExecutionTime::NOW]; + + // remote might only need a confirmation that this is a valid loopback endpoint + if ($token === '__ping__') { + return new DataResponse(['ping' => $this->appConfig->getValueString('core', CoreConfigLexicon::ASYNC_LOOPBACK_PING)]); + } + + $this->async($token); + + try { + $this->forkManager->runSession($token, $metadata); + } catch (BlockAlreadyRunningException) { + // TODO: debug() ? + } + + exit(); + } + + private function async(string $result = ''): void { + if (ob_get_contents() !== false) { + ob_end_clean(); + } + + header('Connection: close'); + header('Content-Encoding: none'); + ignore_user_abort(); + $timeLimit = 100; + set_time_limit(max($timeLimit, 0)); + ob_start(); + + echo($result); + + $size = ob_get_length(); + header('Content-Length: ' . $size); + ob_end_flush(); + flush(); + } + +} -- cgit v1.2.3