laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.75k stars 291 forks source link

Detect cancel request #747

Closed BilalTariq01 closed 12 months ago

BilalTariq01 commented 12 months ago

Octane Version

1.3.0

Laravel Version

9.30.1

PHP Version

8.1

What server type are you using?

Open Swoole

Server Version

1.4.2

Database Driver & Version

jenssegers/mongodb 3.9.1

Description

How can I detect that a request is cancelled from the frontend especially when streaming response? I find that without using the octane php script or request execution stops in the backend when the request is cancelled but with octane, the request keeps running in the backend after cancelling from the frontend.

Steps To Reproduce

 ignore_user_abort(false);
                $stream = new StreamedResponse(function () use ($body, $limits_result, $payload) {
                    $text = '';
                    while (!$body->eof()) {
                        $content = $body->read(10); // Adjust the chunk size as needed.
                        echo "data:" . \json_encode(['message' => $content]) . "\n\n";
                        $text .= $content;

                        // Flush the output to send it to the client
                        ob_flush();
                        flush();

                        // Check if the client is still connected
                        if (connection_status() != 0) {
                            break;
                        }

                    }
}
driesvints commented 12 months ago

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.