I am trying to write some data to a device node in php..It works fine,
however I am having trouble handling errors.
What I want to do is, if the device fails..then prompt the user and
write the data to a file instead.
At the moment if my fopen fails because say the device node doesn't
exist, or is busy, or because my script doesn't have the right
privileges then it can be trapped with something like
if (!$handle = fopen($lpdev, 'w')) {
echo "Cannot write to ($lpdev) Using dump file";
$handle = fopen('/tmp/dump.txt');
}
However if the device node is free but the device on the end of it isn't
responding..it just sits there waiting.
I have also tried
if ($handle = fopen($lpdev, 'w') === FALSE){
echo "Cannot write to ($lpdev) using dump file";
$handle = fopen('/tmp/dump.txt');
}
or trying to trap it with "or die"
None of those seem to work either, if there is nothing responding on
$lpdev (/dev/lp0) the fopen will just sit there trying to write to it
(seemingly for ever)
So I am guessing what I need is some sort of timeout on the fopen after
which it exits and runs the alternative code....but part of me is
thinking that fopen is really meant for files not devices and files are
either there or not and writable or not..hence my trouble.
Am I using a square peg to fill a round hole..or is there a way of
wrapping up the fopen to get it to do what I want.
Help as always is appreciated