Accesing Windows Pipes with PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Im trying to write a PHP application that interfaces
to 
a custom server application using a 
windows pipe. I wrote this code, and am able to send a

query to the pipe, and I get an answer:

-------------------------------------------------------
<?php
$q1 = "<Query><From><Computer>jeplap</Computer>".
"<User>Me</User><TaskID>123456</TaskID>".
"</From><Request><Action>ListUsers</Action></Request>".
"</Query>"; 
$pipe = "\\\\myserver\\pipe\\QueryPipe";
$file = "C:\php\jep.out";

//Open Output file
$f1 = fopen($file,"w");

//Open Pipe
$p1 = fopen($pipe,"r+b");

//Send Query
fwrite($p1, $q1);

//Get query result and write to output file
do {
     $stuff = fgets($p1, 32768);
     fwrite($f1, $stuff);
} while (strlen($stuff) > 0);

fclose($p1);
fclose($f1);
?>
-------------------------------------------------------

The problem is that I am missing part of the begining
of the answer.

The developer who developed the server told me that he
thinks that
the problem is that I am reading the PIPE in FIFO
mode, and that I
am having timming issues. That I have to be able to
read in
message mode, in which I cant read until the whole
message has made
it to the pipe.

I haven't found a way of doing this with PHP
functions. Can PHP
do this?

I am including below the explanation of the developer
of the server app
I am trying to interface with:

-------------------------------------------------------
OK, I know what your problem is. You are accessing the
pipe in the wrong
mode. Pipes can be accessed in a number of ways, I am
guessing that php is
defaulting to a basic FIFO pipe model.

If you refer back to my original documentation, you
will see that the pipe
we use is a full duplex message mode pipe. I'll
explain the difference.

Standard pipe:
Think of a plastic pipe open at both ends, and someone
dropping balls down
the top. The delay between each ball falling out of
the bottom of the pipe
is relational to the delay between inserting them in
the top. Therefore if
you wanted to send 10 balls, you could get a burst of
4, then a delay, then
2 more, then another delay, then another 4.
Relating this to the digital pipe, when you read from
the pipe you are
requesting a maximum of 32768 bytes, however the
number of bytes which you
actually receive will be determined by how many bytes
are already waiting in
the pipe at the time of your request. So it's all down
to timing issues, not
a reliable way! So if 10 bytes are transferred, but
you send a read command
when only 5 are physically in the pipe, then your read
will return with only
5 bytes, as there were only 5 in the pipe at that
point in time. Then you do
another read, and get the remaining 5 (maybe). This is
one of the problems
with 'byte mode pipes' that you have no idea how many
bytes are coming, and
can only read what is available, therefore requiring
you to implement your
own transfer layer in the stream.

Message mode pipe:
Think of the same plastic pipe, but this time with a
valve on the output
end. If the message is 10 long, then all 10 balls are
dropped into the top,
but none come out as the valve is closed. Once the
entire message of 10 is
sent into the pipe, then the value is opened, allowing
all 10 to exit in one
stream. This is basically achieved by using a transfer
layer, invisible to
the programmer, which handles all the handshaking and
packet sizes.

So, your problem is that you are accessing the pipe in
byte mode, and you
need to access it in message mode. I can see that you
are opening your pipe
with "read+binary" flags, is there by any chance a
pipe mode flag in PHP?
The file access commands you are using look very
similar to the old c
standard library calls, which unfortunately are
lacking in features these
days. For example there is no easy way of setting
security attributes,
buffer sizes, interrupt call backs for data completion
etc. Is this the only
way of accessing files / pipes in PHP? Maybe there is
a special pipe command
set?

The other thing I would question is the setting of the
buffer size. I can
see that you are requesting 32768 bytes in the read
command, but this very
different from the internal buffer used with a pipe.
For instance you could
say that the internal buffer is 4k, but you only want
to read 2k. If another
1k of message was sent to the computer while you were
still reading the
first message, then 2+1 < 4 so it would be placed in
the buffer, ready for
the next read to happen. If it can't be placed in the
buffer it becomes a
blocking command at the send or, or times out. So the
read size is a
different entity to the pipe buffer size.


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux