cyril has asked for the wisdom of the Perl Monks concerning the following question:

I am doing a bit of experimenting with using named pipes to read and write data between perl and a php process. The write needs to come from a Perl cgi script. My question is on blocking and I am not sure how I should handle the blocking nature of the write. What I need to do is prevent the write from blocking if the read process has gone away. What kind of checks should I be putting in place? Does the blocking occur when opening the file handler on a named pipe or when I call for a write.

Can anyone help me out with the concepts a little?

thanks
Jon

Replies are listed 'Best First'.
Re: writing to a named pipe
by Zaxo (Archbishop) on Sep 22, 2003 at 23:06 UTC

    You can get a summary of the properties of named pipes from 'man 4 fifo'. If all readers go away and close the other end of the fifo, a SIGPIPE is raised to the writer which tried. You can set up a global variable which is set by $SIG{PIPE} and tested after each write.

    use vars '$no_reader'; $no_reader = 0; $SIG{PIPE} = sub { $no_reader = 1 }; # ...

    You can do a non-blocking open with sysopen. See also Fcntl and perlopentut.

    After Compline,
    Zaxo