named pipes on Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter van Schie

    named pipes on Windows

    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.
    --

  • rh

    #2
    Re: named pipes on Windows


    "Peter van Schie" <vanschie.peter @gmail.comwrote in message
    news:4547cb0d$0 $44503$dbd4f001 @news.wanadoo.n l...
    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


    Comment

    • Jim Carlock

      #3
      Re: named pipes on Windows

      "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.d ll" ( _
      ByRef phReadPipe As Long, _
      ByRef phWritePipe As Long, _
      ByRef lpPipeAttribute s As SECURITY_ATTRIB UTES, _
      ByVal nSize As Long) As Long

      Public Type SECURITY_ATTRIB UTES
      nLength As Long
      lpSecurityDescr iptor As Long
      bInheritHandle As Long
      End Type

      The same thing for MASM:

      CreatePipe PROTO :DWORD,:DWORD,: SECURITY_ATTRIB UTES,:DWORD
      SECURITY_ATTRIB UTES STRUCT
      nLength DWORD ?
      lpSecurityDescr iptor DWORD ?
      bInheritHandle DWORD ?
      SECURITY_ATTRIB UTES ENDS

      And for C#:

      [DllImport("kern el32.dll")]
      public static extern int CreatePipe (
      int phReadPipe,
      int phWritePipe,
      ref SECURITY_ATTRIB UTES lpPipeAttribute s,
      int nSize);
      [StructLayout(La youtKind.Sequen tial)]
      public struct SECURITY_ATTRIB UTES{
      internal int nLength;
      internal int lpSecurityDescr iptor;
      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.



      Comment

      • Peter van Schie

        #4
        Re: named pipes on Windows

        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.
        --

        Comment

        • Peter van Schie

          #5
          Re: named pipes on Windows

          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\mypip e" is being crippled by
          PHP's fopen.
          Therefore a logical workaround is this: using fopen with the machine
          name like this works:

          <?php
          $strComputernam e = php_uname('n');

          $resPipe = fopen("\\\\" . $strComputernam e . "\\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.
          --

          Comment

          Working...