How to stream a long response with stratigility ???

General discussion on PHP
Post Reply
duy2359
Posts: 1
Joined: Fri Apr 13, 2018 5:39 am
Contact:

How to stream a long response with stratigility ???

Post by duy2359 » Fri Apr 13, 2018 5:39 am

I'd like to know how you would go about sending a long response using zend-stratigility and the PSR-7 Response and/or Stream abstractions?

For example, let's say I'm sending a million records in CSV format - I can't put all of this data into the body of a Response object, as it would require too much memory.

With an ordinary PHP script, sending a long response is easy - you just echo the content, and every time the output buffer is full, it's automatically flushed, so you're not using a ton of memory, and the user isn't waiting for the entire CSV file to be generated before the server can start sending the content.

How do you accomplish the same with PSR Response?

I'm assuming it has something to do with the Stream abstraction, but I've never used streams in PHP much, and I'm not sure how this comes into play.

Post Reply