Skip to content

Conversation

@Deltachaos
Copy link

@Deltachaos Deltachaos commented May 10, 2020

Depends on #59

There are two problems with symfony's StreamedResponse:

  1. It uses a callback to generate the whole output using flush in between. This is by design incompatible with a non blocking approach
  2. Symfony\Component\HttpKernel\EventListener\StreamedResponseListener is unwrapping the response before it arrives in the kernel. By this, drift is not able to handle the response and output is not been send to the client.

This PR handles the response by passing output to a BufferStream. From what i have seen, this is not really streaming the response anymore, and it is still not removing the blocking IO from symfony's StreamedResponse approach.

Problems that need to be solved are removing the StreamedResponseListener as it sends the contents before drift can send it. Any better implementation would require changes to the symfony StreamedResponse class.

Copy link
Member

@mmoreram mmoreram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test these new features by adding some controllers returning expected values and checking that the result is the expected one.

We should merge both commits in one as well.

Edit

What's the difference between this PR and #59?

$response->sendContent();
ob_end_flush();
});
} elseif($response instanceof StreamedResponse) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this block is repeated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that was my fault

@mmoreram
Copy link
Member

@Deltachaos Thanks for that PR. I've added some comments before merging.

@Deltachaos
Copy link
Author

have updated the pr

@mmoreram
Copy link
Member

@Deltachaos we already added support for streams in drift.

TBH, doesn't make sense to support any other stream implementation than the ReactPHP one, and as long as we can return a React HTTP Response object with a stream, I think that we are covered.

Thanks for taking care of this.
I appreciate it so much.

@mmoreram mmoreram closed this Aug 28, 2020
@Deltachaos
Copy link
Author

@mmoreram in general I would agree. On the other hand i have created #91 because what i think Drift should try to support is a mode where you can run an application using Drift in async mode, but also in a synchronous mode. This would make the adoption of Drift in existing projects more easy. For this we would require that streamed response implementations are compatible with classic PHP-FPM as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants