Re: Write a FIFO file

From: Date: Tue, 20 Dec 2005 17:20:51 +0000
Subject: Re: Write a FIFO file
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-227736@lists.php.net to get a copy of this message
On 12/20/05, Ruben Rubio Rey <ruben@rentalia.com> wrote: > Robin Vickery wrote: > > >I bet your script will finish as soon as you read from the other end - > >for example by doing 'cat fifo' from a shell. > > > Thats it. > I would like to use fifo, but thats a problem. If there is not process > reading, it wont work. > Is there any way to create process? > Something like: > exec("echo \"My text $var\" > fifo &"); //(This idea does not > work) Named pipes are blocking - if you open one for reading and there's nothing writing then the reading process will be blocked. And as you've just seen, the same happens if you open one for writing and there's nothing reading it. You can change that behaviour by specifying the O_NONBLOCK flag when opening the pipe - if you're opening it for writing, the attempt will fail immediately rather than waiting for something to read. I don't know of a way to do that through fopen(), but you can probably manage it using dio_open() if you *really* want to. It might be better to rethink how your processes communicate? -robin

« previous php.general (#227736) next »