By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,783 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,783 IT Pros & Developers. It's quick & easy.

named pipes on Windows

P: n/a
Hi all,

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.

Peter.
--
http://www.phpforums.nl
Oct 31 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
rh

"Peter van Schie" <va************@gmail.comwrote in message
news:45***********************@news.wanadoo.nl...
Hi all,

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.

Peter.
Have you tried popen() or proc_open()?
Rich
Nov 2 '06 #2

P: n/a
"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.

I haven't messed with this but perhaps it's of some help. The VB
declarations to the API are as follows:

Public Declare Function CreatePipe Lib "kernel32.dll" ( _
ByRef phReadPipe As Long, _
ByRef phWritePipe As Long, _
ByRef lpPipeAttributes As SECURITY_ATTRIBUTES, _
ByVal nSize As Long) As Long

Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

The same thing for MASM:

CreatePipe PROTO :DWORD,:DWORD,:SECURITY_ATTRIBUTES,:DWORD
SECURITY_ATTRIBUTES STRUCT
nLength DWORD ?
lpSecurityDescriptor DWORD ?
bInheritHandle DWORD ?
SECURITY_ATTRIBUTES ENDS

And for C#:

[DllImport("kernel32.dll")]
public static extern int CreatePipe (
int phReadPipe,
int phWritePipe,
ref SECURITY_ATTRIBUTES lpPipeAttributes,
int nSize);
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES{
internal int nLength;
internal int lpSecurityDescriptor;
internal int bInheritHandle;
}

Perhaps someone here can provide an example of how to set up
such API calls inside of PHP and provide an example in this case?

Jim Carlock
Post replies to this newsgroup.
--
Ask The North Carolina Swimming Pool Design Expert
for pricing and details in getting a Sporting Swimming Pool built
in North Carolina.
http://www.aquaticcreationsnc.com/sw...der/nc/ask.php
Nov 2 '06 #3

P: n/a
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.

I haven't messed with this but perhaps it's of some help. The VB
declarations to the API are as follows:
[snip]

Perhaps someone here can provide an example of how to set up
such API calls inside of PHP and provide an example in this case?
Hi Jim and Rich,

Thank you both for your replies. I actually tried using Jim's approach
by using the W32api extension
(http://nl2.php.net/manual/en/ref.w32api.php). However it turned out
that the extension has been removed from the PECL repository.

I just tried Rich's suggestion, using popen() and that actually works.
So thanks a lot I got it working now. :)

Regards,
Peter.
--
http://www.phpforums.nl
Nov 3 '06 #4

P: n/a
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
Nov 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.