How they work and what the concept of streams in PHP

3

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

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

Thanks in advance.

    
asked by anonymous 13.07.2018 / 03:47

1 answer

2

  • 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 (write).

PHP can work with web as it can work on terminals (as a common program), so when using php://input on WEB you will get payload of requests like POST and PUT, if it was sent 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"
    
15.07.2018 / 23:41