Learning PHP Streams

I’m trying to learn more about PHP streams in order to take the Zend Certification exam. This is one area where I am really just having a hard time finding good information to study. Even the Certification Study Guide barely has anything on streams, yet its a topic on the exam and some of the questions on the mock exams related to streams leave me clueless. Question, such as…

“The _________ context variable allows you to define a callback for the stream that will notify your script of certain events during the course of the transaction.”

PHP.net has great documentation of all of the stream_functions, but I’m looking for more of a tutorial on the overall concepts of streams and not just a reference to look up functions.

I own three PHP books and none of them cover streams. They cover the basic file functions… fopen, fread, fwrite, fgets, etc. One of them covers some ftp_functions, but that’s it.

So I ask, where can I learn this stuff? It’s like the one topic I know NOTHING about thats on the exam.

PS. Please don’t say php.net. I’ve been reading stream function definitions on there all afternoon and I’m getting no where.

Chapter 11 is completely about Streams and network programming.
What’s covered there should be enough to pass the exam.
I’ve taken the exam last year and it wasn’t that hard, but if I remind correctly there weren’t many stream related questions in my exam.

Thanks for the response. I did read chapter 11, but was surprised that some of the stream questions on the mock exams have nothing to do with what’s in chapter 11. But like you said, there were only a couple questions so maybe I can afford to miss/guess on those ones if I know the rest of the stuff well.

One other question for you since you’ve taken the exam. There were also questions on Expat XML functions on the mock exams, but no mention of these in the study guide. Since I started using PHP after DOM and SimpleXML were created, I’ve never learned Expat XML (although I realize it’s still faster for certain operations.) Anyway, were there any Expat questions on the actual exam?

…notification paramater, http://us3.php.net/manual/en/function.stream-notification-callback.php

I found that too actually after I finished. But definitely had no clue until I looked it up. Did you know that off the top of your head or have to look it up?

If you skim through the manual, you have a general idea of what the language is capable of, and it makes it easier to find things. It’s something you should do with any language you learn. However, as far as most PHP developers go, I don’t think most of them use or know streams, so most people would probably have to look it up (though they probably wouldn’t know where to look).

I love streams, and I remember anticipating them when PHP 4.2 or PHP 4.3 was coming out. It’s one of the few elegant and well-thought out features of PHP. I wish more people used it, especially over that godforsaken curl.

Someone once asked about streams on here, and I wrote a very basic introduction:

The guy never replied and no one else ever replied to that thread, so I either scared the guy off or he learned on his own. Hence that’s not very complete.

One thing I didn’t mention is that, once you perform a request using streams, there is often metadata that is associated with the stream. For example, if you perform a HTTP request, headers, in addition to the body, is returned. Those headers are considered metadata, and there is a function (stream_get_meta_data()) for getting that metadata.

Also worth mentioning is that file_get_contents() doesn’t let you access that metadata, because it returns the data, not a stream object. If you use fopen(), then you have a stream resource, so you can call stream_get_meta_data().

Thanks for posting. Your post that you linked answered more questions than 3 hours looking through the manual. Do you have any other recommendations for reading up on streams to get more in depth with it?

Says the guy with 10 years of experience. :lol:

http://www.sk89q.com/2010/04/introduction-to-php-streams/

Well, simple thing - it’s like school.
You learn things for an exam that you’ll never use “in the wild”.
Even though I’m doing this job for 10 years now there were things and questions that surprised me.

>Anyway, were there any Expat questions on the actual exam?
No, at least I don’t remember any.

If you’ve read the whole book and taken the mock exams all with a good result you should be on the safe side.

Awesome stuff. Thanks for posting that.