How can I get PHP to talk to pipes?  I know fopen can use php://stdin but can it
also use named pipes (I think I want named pipes, not positive though)?

Perl:

$voice_rfd = new IO::Handle;
$voice_rfd->fdopen( $ENV{VOICE_INPUT}, "r" );

PHP:

$in = "php://" . getenv( "VOICE_INPUT" );
$fd_in = fopen( "$in", "r" );

results in:
[09-Mar-2001 04:17:10] PHP Warning:  fopen("php://4","r") - Inappropriate ioctl
for device in...

I noticed:
"posix_mkfifo - Create a fifo special file (a named pipe)"

Is this what I want (once it is written)?  Or is there something that can
already do this?  Here is my PHP script for reference (if you get worried about
the top couple lines being executed don't be - they do execute properly, vgetty
runs this shell script which spawns a "vm shell" which executes php with $0
which finally runs the php script - everything appears to be running just fine
other than pipes):

#!/usr/bin/vm shell
exec /usr/bin/php -q $0
#!/usr/bin/php4 -q
<?php

//#! /usr/bin/vm shell
//exec /usr/bin/php -q $0

// make use binary fread compatible...
set_magic_quotes_runtime(0);


function voice_receive( $fd_in, $fd_log )
{
        $line = fread( $fd_in, 10000 );
        trim( $line );
        fwrite( "VM: $line\n", $fd_log );
        return $line;
}

function voice_send( $fd_out, $output, $fd_log )
{
        fwrite( "VM: $input\n", $fd_log );
        fwrite( $fd_out, $output . "\n"  );
}

$in = "php://" . getenv( "VOICE_INPUT" );
$out = "php://" . getenv( "VOICE_OUTPUT" );

$fd_in = fopen( "$in", "r" );
$fd_out = fopen( "$out", "w" );
#$fd_in = fopen( "php://stdin", "r" );
#$fd_out = fopen( "php://stdout", "w" );
$fd_cid = fopen( "/tmp/cid.log", "a" );
$fd_log = fopen( "/tmp/vm.log", "a" );
$vm_pid = getenv( "VOICE_PID" );

voice_send( $fd_out, "HELLO VOICE PROGRAM", $fd_log );

$answer = voice_receive( $fd_in, $fd_log );

$name = getenv( "CALLER_NAME" );
$number = getenv ( "CALLER_ID" );

$tmp = "voice input: " . getenv( "VOICE_INPUT" ) . "\n";
$tmp .= "voice output: " . getenv( "VOICE_OUTPUT" ) . "\n";
$tmp .= "answer: " . $answer . "\n";
fwrite( $fd_log, $tmp . "\n" );

fwrite( $fd_cid, $number . "\n" );


fclose( $fd_in );
fclose( $fd_out );
fclose( $fd_cid );
fclose( $fd_log );

?>


Please CC me on replies if possible as I'm not on the lists due to moving mail
servers around...  I'll watch archives though of course :).

Thanks!
Cymen Vig
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to