I/O Streams

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Jackount
Forum Newbie
Posts: 13
Joined: Wed Aug 10, 2011 5:38 am

I/O Streams

Post by Jackount »

I recently heard about I/O Streams, and got curious of how to use it.
I found out PHP had built in (files?) for that. php://stdin, php://stdout, etc,
But though I've googled around and read some articles and stuff,
I still don't get WHAT it (I/O Streams, stdin and stdout) is?
I get that it is standard input and output,
and stdin is read-only, and stdout is writeonly and so on,
but where does it come from - the standard input?
If your write this

Code: Select all

fopen("php://stdin",r+)
What would stdin contain? Why is it considered a file?
And where would the stuff you write to php://stdout go?
can you access php:// in browsers just like http://, ftp://, https://, etc?

I sincerely hope to get these questions answered.
Thanks in advance.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: I/O Streams

Post by Weirdan »

Generally i/o streams are used in the context of console applications, where stdin allows to read what user is typing on the keyboard and stdout allows to communicate something back to the user. Treating them as files is just a useful abstraction because they are not all that different from files. Sockets could also be manipulated just like they were file, so you can use familiar interface for all those interactions.
can you access php:// in browsers just like http://, ftp://, https://, etc?
no, that's a special scheme to tell php runtime you want to access standard streams (like stdin/out, temp, memory, etc). It won't work in a browser.
Post Reply