[PHP] Piping into script...

2001-11-20 Thread Ashley M. Kirchner


If I want to pipe, say an incoming email to a PHP script (assuming I
have php compiled as a cgi binary), how do I deal with when it needs to
receive the stream of data, how to figure out when there is no more
coming before it actually start to parse the information?

And how do people deal with multiple requests and such?  There may
be cases where there could be more than one email incoming at the same
time...while theoretically the MTA only passes them one by one to
whatever's next in line (whether it's procmail, or any other type of
program)

--
H | Life is the art of drawing without an eraser. - John Gardner
  +
  Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
  Director of Internet Operations / SysAdmin. 800.441.3873 x130
  Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave, #6
  http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.



-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread Steve Werby

Ashley M. Kirchner [EMAIL PROTECTED] wrote:
 If I want to pipe, say an incoming email to a PHP script (assuming I
 have php compiled as a cgi binary), how do I deal with when it needs to
 receive the stream of data, how to figure out when there is no more
 coming before it actually start to parse the information?

$fp = fopen( 'php://stdin', 'r' );

Then treat as if its a normal file.  There's nothing special to do.

 And how do people deal with multiple requests and such?  There may
 be cases where there could be more than one email incoming at the same
 time...while theoretically the MTA only passes them one by one to
 whatever's next in line (whether it's procmail, or any other type of
 program)

I don't think you'll have a problem.  Each call to the program should run as
a separate process.  If I'm missing something post some more info.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread David Robley

On Wed, 21 Nov 2001 13:04, Ashley M. Kirchner wrote:
 If I want to pipe, say an incoming email to a PHP script (assuming
 I have php compiled as a cgi binary), how do I deal with when it needs
 to receive the stream of data, how to figure out when there is no more
 coming before it actually start to parse the information?

Steve Werby has answered this for you.

 And how do people deal with multiple requests and such?  There may
 be cases where there could be more than one email incoming at the same
 time...while theoretically the MTA only passes them one by one to
 whatever's next in line (whether it's procmail, or any other type of
 program)

The OS will take care of this by firing up another instance of 
your script. All you need to do is be aware of the possibility of 
multiple instances doing ?things? at around the same time and make sure 
that you don't have say several instances all writing to the same file at 
the same time - use locking where it is not provided by the tool you are 
using.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Flirt: A woman who thinks it's every man for herself.

-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread Ashley M. Kirchner

David Robley wrote:

 The OS will take care of this by firing up another instance of
 your script. All you need to do is be aware of the possibility of
 multiple instances doing ?things? at around the same time and make sure
 that you don't have say several instances all writing to the same file at
 the same time - use locking where it is not provided by the tool you are
 using.

About the only worry I have there is the interaction with the database
itself.  If two scripts start accessing the db for writing at the same time,
I can smell trouble, yes.

--
H | Life is the art of drawing without an eraser. - John Gardner
  +
  Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
  Director of Internet Operations / SysAdmin. 800.441.3873 x130
  Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave, #6
  http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.



-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread David Robley

On Wed, 21 Nov 2001 14:52, Ashley M. Kirchner wrote:
 David Robley wrote:
  The OS will take care of this by firing up another instance of
  your script. All you need to do is be aware of the possibility of
  multiple instances doing ?things? at around the same time and make
  sure that you don't have say several instances all writing to the
  same file at the same time - use locking where it is not provided by
  the tool you are using.

 About the only worry I have there is the interaction with the
 database itself.  If two scripts start accessing the db for writing at
 the same time, I can smell trouble, yes.

That'll be something else burning, then. The DB should be able to handle 
that sort of thing just fine. It is what they are supposed to do, after 
all :-)

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   A bad day on the bike always beats a good day in the office!

-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread Steve Werby

David Robley [EMAIL PROTECTED] wrote:
 On Wed, 21 Nov 2001 14:52, Ashley M. Kirchner wrote:
  David Robley wrote:
   The OS will take care of this by firing up another instance of
   your script. All you need to do is be aware of the possibility of
   multiple instances doing ?things? at around the same time and make
   sure that you don't have say several instances all writing to the
   same file at the same time - use locking where it is not provided by
   the tool you are using.
 
  About the only worry I have there is the interaction with the
  database itself.  If two scripts start accessing the db for writing at
  the same time, I can smell trouble, yes.

 That'll be something else burning, then. The DB should be able to handle
 that sort of thing just fine. It is what they are supposed to do, after
 all :-)

Exactly.  It sounds like you're doing INSERTs so unless you're doing an
UPDATE or SELECT that can give unexpected results if another instance of the
script is running at the same time or you have other scripts accessing the
same files/tables that may run at the same time you're ok.  If there are
potential conflicts look at explicit LOCKing in the database.  FYI,
potential problems related to database and file writes are not just a
product of piping to a script - the same potential exists in web pages doing
the same things when multiple users can access scripts manipulating the same
tables/files simultaneously.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread Ashley M. Kirchner

Steve Werby wrote:

 Exactly.  It sounds like you're doing INSERTs so unless you're doing an
 UPDATE or SELECT that can give unexpected results if another instance of the
 script is running at the same time or you have other scripts accessing the
 same files/tables that may run at the same time you're ok.

Well now, I didn't say I was only doing INSERTs.  After parsing the email, I
need to do a quick select in the DB to see if the customer (placing the order)
already exists in our DB, and if they don't, just plain INSERT.  Otherwise, I
need to do some more work, which will require an UPDATE on that same record.

I'm probably going to break the DB into separate tables (one containing the
customer info, with a matching ID in another table which contains the customer
orders).

(I know, this gets complicated by the minute. ;) )

--
H | Life is the art of drawing without an eraser. - John Gardner
  +
  Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
  Director of Internet Operations / SysAdmin. 800.441.3873 x130
  Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave, #6
  http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.



-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread Steve Werby

Ashley M. Kirchner [EMAIL PROTECTED] wrote:
 Steve Werby wrote:

  Exactly.  It sounds like you're doing INSERTs so unless you're doing an
  UPDATE or SELECT that can give unexpected results if another instance of
the
  script is running at the same time or you have other scripts accessing
the
  same files/tables that may run at the same time you're ok.

 Well now, I didn't say I was only doing INSERTs.

Best guess based on limited information.  My bad.  :-)

 After parsing the email, I
 need to do a quick select in the DB to see if the customer (placing the
order)
 already exists in our DB, and if they don't, just plain INSERT.
Otherwise, I
 need to do some more work, which will require an UPDATE on that same
record.

It sounds like the only possible conflict is if a customer not in the system
places two orders that arrive at about the same time and the second SELECT
is done before the first INSERT is committed.  Experience suggests this
isn't very likely...so unlikely I wouldn't even worry about it unless
there's a reasonable probability that INSERTs would take a long time and new
customers would fire off two orders at the same time (double send in Outlook
or refreshing via a web form?)...and since I don't have all of the details
and I'm likely misinterpreting the whole application I'll leave it at that.

 I'm probably going to break the DB into separate tables (one
containing the
 customer info, with a matching ID in another table which contains the
customer
 orders).

FWIW, that's how I'd approach it.

 (I know, this gets complicated by the minute. ;) )

Definitely harder than a hello world, but it sounds manageable.  Have fun
with it!

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
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]




Re: [PHP] Piping into script...

2001-11-20 Thread Attila Strauss

hi

check this:

http://www.linuks.net/robot.phps

best regards
attila strauss




 
 If I want to pipe, say an incoming email to a PHP script (assuming I
 have php compiled as a cgi binary), how do I deal with when it needs to
 receive the stream of data, how to figure out when there is no more
 coming before it actually start to parse the information?
 
 And how do people deal with multiple requests and such?  There may
 be cases where there could be more than one email incoming at the same
 time...while theoretically the MTA only passes them one by one to
 whatever's next in line (whether it's procmail, or any other type of
 program)
 
 --
 H | Life is the art of drawing without an eraser. - John Gardner
   +
   Ashley M. Kirchner mailto:[EMAIL PROTECTED]   .   303.442.6410 x130
   Director of Internet Operations / SysAdmin. 800.441.3873 x130
   Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave, #6
   http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.
 
 
 
 -- 
 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]
 


-- 
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]