I'm have some php code:
<?
$cmd="mkfifo /tmp/myfifo;";
system($cmd);
$cmd="echo 1 > /tmp/myfifo 2>&1 &";
system($cmd);
?>
on an apache server. I want to have the second command not block. According to the info page of system:
If a program is started with this function, in order for it to continue running
in the background, the output of the program must be redirected to a file or
another output stream. Failing to do so will cause PHP to hang until the execution
of the program ends.
But I don't see how to apply that to this situation. I tried
$cmd="echo 1 > /tmp/myfifo > /dev/null 2>&1 &";
But to be honest that seems nonsensical.
EDIT:
My ultimate goal is to write to a fifo that may never be read from, and time out the write after 5 seconds. So, if I can manage to get this command to not block the php executition, I can sleep 5 seconds and then cat /tmp/myfifo > /dev/null 2>&1 to unblock the original write.
Can anyone think of a better way to have my write not hang indefinitely (in neither the background nor the foreground)?
system()calls?