Getting PHP to process input from STDIN
| From: | Danny | Date: | Sun, 24 Jan 2016 17:40:51 +0000 |
| Subject: | Getting PHP to process input from STDIN | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-325363@lists.php.net to get a copy of this message | ||
Hi,
I am trying to process the body of a message that is piped from Procmail to a
php-cli script with no luck ... I am trying to only catch the body of the
message ... no other formatting ... mime etc ... only the body which consists of
a one line message that is max 96 characters long ... the message in the body
will start with a 0(zero) and end with a 0(zero) ...
Here is my script:
######################################################################################################
#!/usr/bin/php
<?php
$get_mail_body = fopen ( 'php://stdin', 'r' ) ;
$mail_body = preg_match ( "/[0]*?[0]/", @$get_mail_body, $body_match,
PREG_OFFSET_CAPTURE ) ;
while ( $message = fgets ( $get_mail_body ) )
{
if ( $message == $body_match[0] )
{
$command = exec ( 'echo -e "\rLT 4>'.$body_match[0].'r\r" >
/dev/ttyS1' ) ;
}
else
{
}
}
echo "$command" ;
fclose( $get_mail_body );
?>
######################################################################################################
And here is my procmail recipe:
######################################################################################################
:0
* ^Subject.*Aprs message$
{
:0 bf
!
/usr/bin/php -f /usr/local/bin/scripts/aprs_messages.php
}
######################################################################################################
Any pointers?
Thank You
Danny