[nycphp-talk] How HTTP connection life relates to PHP script life

Anirudh Zala (Gmail) arzala at
Tue Jun 21 00:49:44 EDT 2005

Hi J,

A: Once you hit submit button in any page, request is immediately sent to
Server and then Php script is executed even if you hit stop button and
navigate through other pages or do other stuffs, and since you are not on
that page you will not get any response sent back that script to your once
it's task is finished.

B: You are right sending any kind of mails more than few hundred is never a
good practice to follow, because it is almost a back end task to be
performed by any script hence keeping page open or increasing server time
out  until script sends all mails is not good option at all. So CLI script
is best option since it has not any timeout that happens while running
script through Apache and it lasts as long as you wish to perform background

What you want to do is proper option according to my knowledge, another
similar option is to divide this functionality in 2 parts:

1: determining how many mails are to be sent based upon selection criteria
submitted by admin and determines how many mails are to be sent and display
that number to user who is running this script (please note mails will not
be sent at this moment) instantly and store that Sql criteria or part of
script in DB.

2: and next day at early morning or at same day at midnight invoke another
script by cron etc. which executes stored Sql criteria and actually sends


Anirudh Zala

----- Original Message -----
From: "Jayesh Sheth" <jay_nyphp at>
To: <talk at>
Sent: Tuesday, June 21, 2005 8:50 AM
Subject: [nycphp-talk] How HTTP connection life relates to PHP script life

> 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
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP

More information about the talk mailing list