aendeerei aendeerei - 1 month ago 10
PHP Question

How to use PSR-7 Request streams

I really hope, you could help me.

I'm implementing my PSR-7 Request class and I have problems understanding


  • What are the streams used for in PSR-7 Request?

  • Which stream wrappers must be used in PSR-7 Request?



It's not only about understanding the concept in general, but just beeing able to model it in PHP after I receive your answers. Right now I'm confused in this context.

Thank you very much for your time!

P.S: I would have put a bounty of 200 on this question. But today I can't. I will do this in exactly two days.

Answer Source

What are the streams used for in PSR-7 Request?

Streams are where your request and response bodies are stored. They are used as an alternative to a string. A string might have worse performance if they are particularly big, which is why streams are used instead.

Which stream wrappers must be used in PSR-7 Request?

Any streamwrapper is completely fine. As long as it's a stream. So if you are doing a HTTP request and want to upload a file from disk, you can use a standard file stream. If you making a Request object and you're doing a server-side implementation, you will probably want to use php://input. If you are making a client, and want to just define the HTTP request body as a string, the easiest will be to convert the string to a stream using the memory:// or temp:// wrapper.