|
Posted by Peter van Schie on 11/11/06 13:23
Peter van Schie schreef:
> Jim Carlock schreef:
>> "Peter van Schie" :vanschie.peter at gmail.com: asked:
>> : I'm trying to create a named pipe to communicate with another
>> : application from a PHP application. The thing is that I cannot use any
>> : of the posix functions on Windows, including posix_mkfifo.
>> : Is there any other way to create a named pipe and if so.... how?
>> : Thanks in advance.
>>
Here's an update for this issue, because I found the solution and it
might be useful to other people in the future.
popen() returned true, but that didn't mean it worked. As the php docs
state: "If the command to be executed could not be found, a valid
resource is returned. This may seem odd, but makes sense; it allows you
to access any error message returned by the shell".
I then walked into this bug report: http://bugs.php.net/bug.php?id=29005
The bug report states that the dot in a filepath is being interpreted as
"current directory" by php. This is still true in the current stable PHP
version 5.2 and even in the latest PHP 6 snapshot.
So a named pipe path such as: "\\.\pipe\mypipe" is being crippled by
PHP's fopen.
Therefore a logical workaround is this: using fopen with the machine
name like this works:
<?php
$strComputername = php_uname('n');
$resPipe = fopen("\\\\" . $strComputername . "\\pipe\\mypipe", "w");
if ($resPipe === false)
{
echo 'Failure';
}
else
{
echo 'Success';
fwrite($resPipe, "foo");
fclose($resPipe);
}
?>
I hope this is useful to someone in the future. :)
Regards,
Peter.
--
http://www.phpforums.nl
Navigation:
[Reply to this message]
|