-
-
Notifications
You must be signed in to change notification settings - Fork 46
Conversation
c189d77
to
3123f7e
Compare
Thanks @supersmile2009 for PR, overall I think this is a really good feature, but I'll have to take more time to review it properly because I do not like the idea of keeping swoole request/response objects in symfony's request/response objects. Obviously, you can add general feature tests, which should be working anyway, even with a little bit different implementation of this feature |
@k911 what about creating SwooleContext service - a simple service to contain Swoole's Request and Response objects? We could set both request and response into it from HttpKernelRequestHandler. Then this Context could be injected into StreamedResponseListener (or any other service in future if anyone needs original Swoole's request/response for any reason). To be honest I'm not a big fan of either of these solutions. But at least with the current implementation with the use of request attributes there are not stateful services, so no reliance on ResetInterface and no potential side-effects. And all interaction with the attributes is done through the SwooleRequestResponseContextManager, so attribute names are encapsulated. |
Anyway @supersmile2009 why not just process this response in |
@supersmile2009 Please check out this approach https://github.com/supersmile2009/swoole-bundle/pull/1/files (Rebase your PR onto develop, to get clean changes) |
3123f7e
to
f357a4c
Compare
Same reason as why Symfony has StreamedResponseListener instead of sending response in index.php like it does for other types of responses. I briefly explained it in the PR description:
I wouldn't want to complicate it, but this is the way this feature was designed in Symfony, so I'm just trying to make it work the same way with Swoole. One of the changes that I did which I didn't really like was this piece in K911\Swoole\Bridge\Symfony\HttpKernel\HttpKernelRequestHandler
Reasons:
So I updated that part. Please have a look at the last 2 commits. Now request processors are a stack of decorators. |
src/Bridge/Symfony/HttpFoundation/ResponseHeadersAndCookiesProcessor.php
Outdated
Show resolved
Hide resolved
src/Bridge/Symfony/HttpFoundation/StreamedResponseProcessor.php
Outdated
Show resolved
Hide resolved
src/Bridge/Symfony/HttpFoundation/StreamedResponseProcessor.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @supersmile2009 for explanation, let's go with this approach. Let me know if you'll have some troubles with unit testing / feature tests so we can get this merged
@supersmile2009 I just wanted to kindly remind you of this PR, please tell me if you need any help or don't want to continue your work. |
Hi @k911 |
@supersmile2009 Great, thanks for an update! :) PS. Good luck with the release :) |
f26a869
to
86ee1d2
Compare
@k911 PR is updated with all the requested changes. |
Hi, @supersmile2009 thanks. Unfortunately CI and some tests failed. I'll take a look at this closer probably next week, however feel free to update PR, too - if you know what's going on. |
anything I can help with to make this release? |
Hi @Webonaute, we need to resolve problems that occurred during CI build, which are Unit tests /code style issues, then make sure we tested everything properly via feature tests. I think that if @supersmile2009 won't be able to finish work here, you could fork his branch and fix that issues. |
391b1d1
to
e89c7b5
Compare
Codecov Report
@@ Coverage Diff @@
## develop #300 +/- ##
=============================================
- Coverage 85.65% 85.61% -0.04%
- Complexity 644 661 +17
=============================================
Files 91 97 +6
Lines 2028 2078 +50
=============================================
+ Hits 1737 1779 +42
- Misses 291 299 +8
|
Hi @supersmile2009, thanks for the changes. This weekend I'll try to add some missing tests for this & finally cut a release |
e89c7b5
to
a3be066
Compare
@k911 I've fixed the failing tests and added a test for the new response handlers. To mitigate that I'd recommend moving php-cs-fixer away from composer dependencies. CI should always install explicitly when needed (i. e. in code style job) and use the latest version (e. g. download it with curl). It will not only eliminate the issue of different rule sets, but also make sure nothing slips out unchecked/unfixed due to the bugs in older php-cs-fixer versions. Also it doesn't make much sense to run the php-cs-fixer with different dependency versions. In fact it can run with no dependencies installed at all, making the pipeline even faster. |
Code Climate has analyzed commit 6e495e2 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 88.1% (50% is the threshold). This pull request will bring the total coverage in the repository to 85.6% (0.0% change). View more on Code Climate. |
@supersmile2009 Thanks for your update. As I commented before I agree that cs fixer issue is definitely out of scope for this PR. Although, I cannot agree with other points listed due to various reasons:
IMO there aren't any benefits in not running them on multiple environments except wrong impression of having faster CI process, which then could cause issues that would have to be spotted manually. Also, if a tool produces different results across all supported versions it clearly means that we support incompatible version ranges and they have to be adjusted. |
hi @k911 and @supersmile2009 :) I just found out that this feature just broke the development workload in our company. What woud you say about an alternative approach to this problem, decoupled from swoole? it's quite similar to the firt approach of this PR - just with the change, that I would propose to set a callback attribute to the Symfony Request (on swoole to symfony request conversion). The callback would contain the code from the current StreamedResponseProcessor and the listener would use the callback from the request, if there was one, or it would run the code from the original symfony StreamedResponseListener if there would be no callback. What would you say about this? I can implement it, but at first I'd like to know if the design is ok with you |
Hi @Rastusik, sure please propose PR from what I understood it's seems fine. Also, due to the fact that I treat this project more like a hobby and you're using it on production I must suggest that you should fork it internally in case you need to fix issues immediately and then you could backport features also to your codebase (and of course fixes here are most welcome) P.S. With swoole I spend endless amount of hours trying to understood what is happening and why it isn't working especially when it comes to coroutines and testing (e.g.: https://app.circleci.com/pipelines/github/k911/swoole-bundle/1243/workflows/e5b1aecf-9ca6-4441-84c5-97a7234d9e72/jobs/14974 works ok, until it does not..). So I think you should reconsider using it on production, I found it working quite stable only for simple stateless (JSON) API applications (without ORM) or simple web servers. So good luck! :) |
hi @k911 ok, I'll make a PR regarding the forks, I would do it if there would be issues happening more frequently, but they aren't, and we always were able to workaround them when there were some, so I don't see a problem there regarding production deployment - our app based on this bundle is serving cca 30 000 concurrent users daily for a year now and it was never unstable. It's a stateless app, but it uses Doctrine. So I'm not really afraid. Maybe what is hard to do is writing the tests, but on the app side it works well (we're still not using coroutines, but we plan to and that will be the time, when I can look at it too and help to improve the tests) |
This PR adds support for StreamedResponse by making use of PHP's output buffering functions.
It's designed to behave as close as possible to original StreamedResponse handling when running Symfony with php-fpm. Compiler pass replaces Symfony's Symfony\Component\HttpKernel\EventListener\StreamedResponseListener with a custom listener, which triggers returning response to the client. The reason listener is used instead of simply calling the response processor from the HttpKernelRequestHandler is the same as originally in Symfony - a callback in StreamedResponse may depend on some services, which depend on Request context (current Request being present in RequestStack). Also error handling that you have in your Symfony app can kick in if the callback fails, which is not the case if we process the StreamedResponse outside of the request context.
Before I start writing tests, please let me know first if the overall design of this solution looks good to you, or you'd rather take some different approach.