From 8706d58ea68fa395ee73efaad6e0f99fbcfbadf3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 18 Jan 2024 12:39:45 +0100 Subject: [PATCH] Move code only if required --- htdocs/api/index.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 76a09ae254e..2f6bac8452d 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -434,18 +434,19 @@ if (Luracast\Restler\Defaults::$returnResponse) { echo $result; } -// Now flush output buffers so that response data is sent to request client -ob_end_flush(); - -// If you're using PHP-FPM, this function will allow you to send the response and then continue processing -if (function_exists('fastcgi_finish_request')) { - fastcgi_finish_request(); -} - // Call API termination method $apiMethodInfo = &$api->r->apiMethodInfo; $terminateCall = '_terminate_' . $apiMethodInfo->methodName . '_' . $api->r->responseFormat->getExtension(); if (method_exists($apiMethodInfo->className, $terminateCall)) { + // Now flush output buffers so that response data is sent to the client even if we still have action to do in a termination method. + ob_end_flush(); + + // If you're using PHP-FPM, this function will allow you to send the response and then continue processing + if (function_exists('fastcgi_finish_request')) { + fastcgi_finish_request(); + } + + // Call a termination method. Warning: This method can do I/O, sync but must not make ouput. call_user_func(array(Luracast\Restler\Scope::get($apiMethodInfo->className), $terminateCall), $responsedata); }