[nycphp-talk] How HTTP connection life relates to PHP script life
Jayesh Sheth
jay_nyphp at fastmail.fm
Mon Jun 20 23:20:07 EDT 2005
Hello all,
I am sorry if this message went through twice. The first time I stupidly
posted it from the wrong email address (that was not subscribed to this
list).
I have a rather interesting and multi-faceted question, but since it's
nearing my bed-time, I will try to type a few coherent lines before I
doze off at the keyboard.
Here's the deal:
Suppose you have a PHP application, which is running in the traditional
PHP way:
1) A user visits http://localhost/mailings/send_newsletter.php
2) The user selects a list, pastes in a letter, and pressed 'Submit'
3) The browser open an HTTP connection, and Apache processes the
request.
4) Apache passes the script to the PHP 4 module (not to a PHP 4 CGI
binary)
5) PHP looks up all the addresses in a MySQL table for the chosen list,
loops through them, sends an email to each person on the list. After
each message is sent, a confirmation message is echoed.
Now for the questions:
a) If a the user hits the stop button or navigates to another page, will
Apache realize that the HTTP connection has been closed and thus
terminate the script? If not, will it keep running, and if so for how
long?
b) I know this is not the best way to do it. What are your opinions on
the following method: the PHP script should invoke a command line (CLI)
script that runs as a separate process through the PHP CLI binary. That
process writes how many emails it has sent to a MySQL table or to a
file. The user's page simply META-refreshes, polls the MySQL table or
log, and says 'x messages sent, y to go'.
c) Are there any things that I am missing here?
Thanks in advance.
Best regards,
- Jay
More information about the talk
mailing list