-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force close HTTP request/response #186
Comments
You mean |
@JanTvrdik Maybe yes, but this function can be sometimes unavailable: |
Then I don't understand this issue. You cannot implement this in userland. |
ping @janbarasek |
@dg I'm not sure this is Nette's responsibility, but it would be nice to be able to control all the output to the browser via the For example, a user invokes a long-running task in the Presenter, so I send him a quick response (Latte template), but the task continues to run in the background even after the user closes the connection and all headers are sent correctly. This allows, for example, to respond to a request very quickly, but to write data to the database only after the user does not have to wait for it. If this does not make sense, please close the issue. Thanks. |
The question is, how to implement it? Is there a function for that? |
There are some attempts in comments: https://www.php.net/manual/en/features.connection-handling.php For such long-term running cases, I usually render ordinary response and from browser then, invoke WebSockets/Ajax request with |
Before any output is sent
When connection should be closed, output sent and script continue:
It should do the trick, but be beware of possible issues:
@milo Good job, you was faster :D |
But ignoring the implementation question - there are imho better options for non-blocking processing like message queues, swoole and possibly fibers in the near future. |
Wouldn't it be better to write a feature request on PHP? |
@mabar I think the magic is only in Content-Length header. |
Cannot be solved in PHP. |
The Response service could include a method to force the termination of the current HTTP request.
This can be very useful if I want to send output to the user but continue running the script and, for example, finish saving to a database that the user does not have to wait for.
The use may be suitable for an API that stores data, but also for a Presenter that has already submitted a template and the user does not have to wait for background operations to complete.
If Tracy is active, it should prevent this feature from being rendered.
I could implement this feature myself, but I think the native support is great.
Thanks!
The text was updated successfully, but these errors were encountered: