Re: streams, stderr/out and zend_fprintf ?

From: Date: Wed, 07 May 2003 15:28:50 +0000
Subject: Re: streams, stderr/out and zend_fprintf ?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-1357@lists.php.net to get a copy of this message
--- Wez Furlong <wez@thebrainroom.com> wrote: > > > On Tue, 6 May 2003, Hans Zaunere wrote: > > I don't have to deal with Solaris, fortunately. However, I'm unclear as > to > > what I've described that makes it sound like I don't need to use the > streams > > API. Because it's primarily a CLI extension? Or because I'm talking to > a > > serial port? > > Both ;) > Usually, you will want to perform low level operations on the serial > port using ioctl() or other library functions that expect to work with > the fd. Also, you might not want to have any buffering at all; so it > sounds like you don't need a stream. (but read on...) > > > My initial take on getting the serial device online was to use a > resource, > > defined as (where msr is the name of the device): > > > > typedef struct { > > int filedes; > > struct termios sio; > > } msr_resource; > > > > Thus, also having init and destructor functions to open(), cfmakeraw(), > > cfsetspeed(), tcsetattr() and close() the returned filedes. > > > > Then it hit me that php.net/streams says a stream is already a resource > with > > many of the resource housekeeping tasks taken care of. Great, but then > how > > can I set my serial options on a php stream (like cfmakeraw, for > example)? > > > > I see the ability to cast a php_stream to a filedes, but vice-versa, or > as > > you said "you can open a php stream around an existing file descriptor," > I'm > > having no luck? > > > > php_stream_fopen_from_fd() is present in 4.3.2 and later (try a snapshot > from snaps.php.net), however, it sounds to me like you *might* benefit > from implementing your own stream. (depends on how complex your API is). Ahh, that's where the function is. The protocol this serial device uses isn't very complex, and in fact I already have it written using the POSIX salute (open/read/write). So you may ask "why even waste time with all these streams questions?" and I would say "because I have some extra time at work and wanted to see where it'd take me" :) > > Perhaps I'm making it overly complex, and simply using a > resource->filedes is > > the way to go, but I'd like to get familiarized with php streams. Any > > additional tips would be helpful. > > If you are tempted to implement your own streams, I recommend reading my > articles in PHP Magazine </plug> and/or the content from my Streams talk > at the International PHP Conference in Amsterdam this week </plug> ;) > > (I'm more than half serious here) I had hoped to get to Amsterdam but it's not going to happen. Best of luck with the presentation and I'll see if I can get my hands on those articles. > For starters, check out the API docs for streams at php.net/streams; > although by no means complete, its better than nothing; they focus more > on using the streams API than implementing streams. > > Its hard to advise you on which is the "best" approach for your > extension without really knowing what it does, or what functions it > exposes to PHP user-land. Generally, it is best to keep it simple > (KISS), so it might make you life easier to go with the structure you > described and make it into a resource, but replace the "int fildes" with > "php_stream *stream". After chasing the definition of php_stream down the rabbit hole, I think I'll stick with what I know for now :) It's a very exciting prospect, though, and I'm anxious to work with it in more interesting and appropiate projects. > Hope that helps :) Very much so, thanks for the pointers all H

« previous php.internals (#1357) next »