Jump to content

Recommended Posts

I'm sure there is quite an obvious flaw in my php :( I have a process that I want to pipe text to, and then receive text back from. I know the process that I am piping to and receiving from works, because I knocked up a perl script to do what I want php to do and everything worked just hunky-dory. It seems to be hanging at the fread command, I know my process is getting the text from php, and firing a reply back but the script isn't receiving it. Here is my php code:

 

<?php
$pipe_there=fopen('/tmp/my_pipe','r+');
fwrite($pipe_there,'voila du text');
fclose($pipe_there);
$pipe_back=fopen('/tmp/my_other_pipe','r+');
$output=fread($pipe_back,1000);
fclose($pipe_back);
?>

 

Any help would be greatly appreciated.

does my_other_pipe contain any text?

 

Yes, at least, I'm as sure as I can be that it does. Here is a perl script that I made that does what I want php to do:

 

#!/usr/bin/perl
use Fcntl;
$input="some random text\n";
sysopen(FIFO,"/tmp/my_pipe", O_WRONLY);
print FIFO $input;
close FIFO;
print "input sent : $input";
sysopen(FIFO,"/tmp/my_other_pipe", O_RDONLY);
@output=<FIFO>;
close FIFO;
print  @output;

 

If I run this, it will pipe text down /tmp/my_pipe and get a response down /tmp/my_other_pipe. I'm confused..

You're opening the file in read-only mode the first time I lied:

<?php
$pipe_there=fopen('/tmp/my_pipe','w');
fwrite($pipe_there,'voila du text');
fclose($pipe_there);
$pipe_back=fopen('/tmp/my_other_pipe','r');
$output=fread($pipe_back,1000);
fclose($pipe_back);
?>

 

EDIT: Didn't see the r+.  >_<  I changed my code a bit, so try it now.

Worked perfectly. Hum. Now I feel really silly. I only stuck it on r+ because th e first blog posting I read on the subject suggested that not doing so would break the pipe. Should've checked that..

 

*slaps forehead*

 

Thanks for your help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.