php + stdin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skolar
Forum Newbie
Posts: 11
Joined: Mon May 09, 2005 12:36 pm

php + stdin

Post by skolar »

I'm trying to write a script that reads emails and acts as a filter for incoming emails.

When i send an email, i have it setup to go to the script with qmail and the script is being called. however, i cant seem to get the email (neither contents nor headers) sent to the script. From what i've seen, its supposed to be sent in php://stdin which is what i'm trying to read from.

Here's my code:

$fp = fopen('php://stdin', 'r');
$email = fread($fp, filesize('php://stdin'));
fclose($fp);

However i keep getting this error:

PHP Warning: filesize(): Stat failed for php://stdin (errno=2 - No such file or directory) in /home/httpd/vhosts/getbounty.com/redir.php on line 13

I dont know why this is happening.

Here is what i have in my .qmail file :
| /path/to/my/php/script.php


Any help would be much appreciated. Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

filesize() uses the stat() function to retrieve size information. stat() only works on existing files. php://stdin isn't a file, it's a stream, therefore has no size.

You are supposed to loop over the incoming lines until you reach the end of the email.
skolar
Forum Newbie
Posts: 11
Joined: Mon May 09, 2005 12:36 pm

Post by skolar »

awesome...it seems to work now. You i got the idea for using filesize from "The PHP Anthology - Object Oriented PHP Solutions: Vol 1"

Could it be a bug in the book?

Thanks again.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from what I know, stdin has never supported and will never support stat(), so I call bug.
Post Reply