How they work and what the concept of streams in PHP is

Asked

Viewed 167 times

3

I would like to know how it works and what the concept of streams is. I’ve used streams to get input, I also know there are others to control output. However, I would like to know the theory and where the idea comes from in PHP.

OBS: I would like to know the idea of streams in general and not only in relation to input and output through the protocol php://.

From now on, thank you.

1 answer

2


This is not about PHP, input and output are basic use in any computer program, in PHP there are protocols to facilitate:

  • php://stdin
  • php://stdout

and can be used with fopen, file_get_contents (read), file_put_contents (write) among other read functions (such as copy).

Now for HTTP, ie WEB pages, you should use:

  • php://input
  • php://output

That can be used with fopen, file_get_contents (read), file_put_contents (record).

PHP can work with web as it can work on terminals (like a common program), so when using php://input in WEB you will get the payload of requests like POST and PUT, if you sent this via HTTP request:

POST /foo/bar.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded

foobar=boobaz&toofoo=ever

The file_get_contents('php://input') would return:

"foobar=boobaz&toofoo=ever"
  • 1

    @rcs it is impossible to edit comments with more than 5 minutes, IE they have more than 3 months, then the time has passed enough, but I will delete pq I think we talked what was necessary and we can follow from here, I’m running out of time, but soon I’ll list the Wrappers and notify you ;)

  • 1

    @opa opa everything yes, done, I tried to explain more clearly in the reply, I hope it helps.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.