benjumanji Posted August 13, 2008 Share Posted August 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/119568-solved-sending-to-and-receiving-from-named-pipes/ Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 does my_other_pipe contain any text? Link to comment https://forums.phpfreaks.com/topic/119568-solved-sending-to-and-receiving-from-named-pipes/#findComment-615990 Share on other sites More sharing options...
benjumanji Posted August 13, 2008 Author Share Posted August 13, 2008 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.. Link to comment https://forums.phpfreaks.com/topic/119568-solved-sending-to-and-receiving-from-named-pipes/#findComment-615994 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/119568-solved-sending-to-and-receiving-from-named-pipes/#findComment-615996 Share on other sites More sharing options...
benjumanji Posted August 13, 2008 Author Share Posted August 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/119568-solved-sending-to-and-receiving-from-named-pipes/#findComment-616005 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 No problem. =) Link to comment https://forums.phpfreaks.com/topic/119568-solved-sending-to-and-receiving-from-named-pipes/#findComment-616008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.