By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

connection drops while script running

P: n/a
I have a pretty basic emailing script that sends a relatively small number
(150) of html emails.
The emails are compiled, personalised from a mysql db subscribers list,
and sent using mail() - after sending, a small summary html page is sent to
the user with number sent, time taken and a simple navigation choice. Up to
about 100 emails it all works fine - this takes the server about 27 secs .
Any more than that and although the emails are sent ok the connection to the
browser appears terminated - it looks like a 30 sec timeout. The user is
left with a 'connection failed' screen in the browser and the worrying
sensation that the send has failed.

I have the max_execution_time set for 90 secs, (this can be set locally with
a php.ini on an individual directory basis on this server) , no error
messages are sent, and the script obviously completes the emailing (as, on
test, they all arrive). http_connection is set globally on the server to
Keep-Alive .It's apache/linux on the server.

I have an ongoing support ticket with the host company but so far no helpful
response. It feels distincly like a server decision but that's not my area -
I dont know the right questions.

Are there any techniques for keeping the connection alive while a longish
script executes?
Any suggestions?
Feb 15 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
This wrote:
I have a pretty basic emailing script that sends a relatively small number
(150) of html emails.
The emails are compiled, personalised from a mysql db subscribers list,
and sent using mail() - after sending, a small summary html page is sent to
the user with number sent, time taken and a simple navigation choice. Up to
about 100 emails it all works fine - this takes the server about 27 secs .
Any more than that and although the emails are sent ok the connection to the
browser appears terminated - it looks like a 30 sec timeout. The user is
left with a 'connection failed' screen in the browser and the worrying
sensation that the send has failed.

I have the max_execution_time set for 90 secs, (this can be set locally with
a php.ini on an individual directory basis on this server) , no error
messages are sent, and the script obviously completes the emailing (as, on
test, they all arrive). http_connection is set globally on the server to
Keep-Alive .It's apache/linux on the server.

I have an ongoing support ticket with the host company but so far no helpful
response. It feels distincly like a server decision but that's not my area -
I dont know the right questions.

Are there any techniques for keeping the connection alive while a longish
script executes?
Any suggestions?
It sounds like perhaps your browser is timing out, not the server.
Nothing you can do about that from the server side.

So just use the PHP script to create a message template and queue the
information, then do the actual personalization and emailing in a batch job.

It also means your user isn't waiting 5 minutes for a response.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Feb 15 '08 #2

P: n/a
On Feb 15, 1:44 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
This wrote:
I have a pretty basic emailing script that sends a relatively small number
(150) of html emails.
The emails are compiled, personalised from a mysql db subscribers list,
and sent using mail() - after sending, a small summary html page is sent to
the user with number sent, time taken and a simple navigation choice. Up to
about 100 emails it all works fine - this takes the server about 27 secs .
Any more than that and although the emails are sent ok the connection to the
browser appears terminated - it looks like a 30 sec timeout. The user is
left with a 'connection failed' screen in the browser and the worrying
sensation that the send has failed.
I have the max_execution_time set for 90 secs, (this can be set locally with
a php.ini on an individual directory basis on this server) , no error
messages are sent, and the script obviously completes the emailing (as, on
test, they all arrive). http_connection is set globally on the server to
Keep-Alive .It's apache/linux on the server.
I have an ongoing support ticket with the host company but so far no helpful
response. It feels distincly like a server decision but that's not my area -
I dont know the right questions.
Are there any techniques for keeping the connection alive while a longish
script executes?
Any suggestions?

It sounds like perhaps your browser is timing out, not the server.
Nothing you can do about that from the server side.

So just use the PHP script to create a message template and queue the
information, then do the actual personalization and emailing in a batch job.

It also means your user isn't waiting 5 minutes for a response.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
had a similar problem these days.
Is output_buffering set to a default value( output_buffering!=0 )?
You have to output something so that the browser will not close the
connection after HTTP_KEEP_ALIVE (which i belive is 30s by default
anyway). The connection is closed by the browser,not by the server...

If output_buffering is set, than you have to send that many bytes, so
the browser actually receives something, so it will not consider the
connection as timed-out.
Feb 15 '08 #3

P: n/a
So... let me explain the browser mechanism (from i had understand the
other day when i had similar problems)

The browser send a header to the server, with HTTP_KEEP_ALIVE .
Generally this is set to 30 (seconds). I do belive it is a server
config..but 30s should be enough anyway.

The thing is that php uses "output_buffering" which means that when
you call echo "x" from php, the x is not sent imediatly to the
browser, but it is stored temorarly in the "output_buffer.". When
output_buffer grows too large it is flushed to apache, which should
send it to the browser. Funny thing, you can also set an
output_buffering for apache too... So that if output_buffering is 0
and you do and "echo x" that "x" is not sent imediatly to the
browser...

From what you see, before anythinng is received by the browser , there
are a few buffers in the way, which you cant control reliably.

Now..from the browser point of view, he has sent HTTP_KEEP_ALIVE with
30 seconds set. This means that "if in 30 seconds i do not receive
anything from the server, kill the connection without notice". If
thebrowser kills the connections the server will not have a chance to
try and flush the buffers. This is why you do not see any data coming
from the server.

The solution is to make some outputs... when i had this problem i
already made some outputs with debug information, but these outputs
were put in a hidden div (i was using AJAX, so the process could be
controlled from the browser-side, in case i needed to stop/restart
it). So, in my case, setting output_buffering to 0 was enough.

If you want to run proceeses in background, i suggest using cron, or
exec(), so you will not limit the browser.
If you do this sort of long-running operations in the browser, then
there are many chances that the browser-server connstion would drop
for eaxmple. And in this case apache will kill the php process which
is running the emailing stuff.

Also, be sure that there is no time limit to your script(if a lime-
limit is in effect, you should see a "timeout exceed" error after the
timeout has expired).
Also , be carefull with session expiring during script execution. Try
to close the session in advance(session_write_close()) and by doing
this you will also be able to view other pages while the emailing
script is running.

There is not one-size fits all when running background srcipts. It
depends on the OS the server is running, the php settings, tha apache
settings..etc.

You also could change your script to "automatically" restart every 25
seconds ( send a header of Location: index.php?x=rand() ) , and
continue sending emails from the point it had remained... but i dont
see this as a very elegant solution:)
On Fri, Feb 15, 2008 at 3:58 PM, Mick Gahagan <in**@thisinternet.com>
wrote:
>
----- Original Message -----
From: "_q_u_a_m_i_s's" <qu****@gmail.com>
Newsgroups: comp.lang.php
Sent: Friday, February 15, 2008 12:05 PM
Subject: Re: connection drops while script running

On Feb 15, 1:44 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>This wrote:
I have a pretty basic emailing script that sends a relatively small
number
(150) of html emails.
The emails are compiled, personalised from a mysql db subscribers
list,
and sent using mail() - after sending, a small summary html page is
sent to
the user with number sent, time taken and a simple navigation choice.
Up to
about 100 emails it all works fine - this takes the server about 27
secs .
Any more than that and although the emails are sent ok the connection
to the
browser appears terminated - it looks like a 30 sec timeout. The user
is
left with a 'connection failed' screen in the browser and the worrying
sensation that the send has failed.
>>
I have the max_execution_time set for 90 secs, (this can be set locally
with
a php.ini on an individual directory basis on this server) , no error
messages are sent, and the script obviously completes the emailing (as,
on
test, they all arrive). http_connection is set globally on the server
to
Keep-Alive .It's apache/linux on the server.
>>
I have an ongoing support ticket with the host company but so far no
helpful
response. It feels distincly like a server decision but that's not my
area -
I dont know the right questions.
>>
Are there any techniques for keeping the connection alive while a
longish
script executes?
Any suggestions?
>>
>It sounds like perhaps your browser is timing out, not the server.
>Nothing you can do about that from the server side.
>>
>So just use the PHP script to create a message template and queue the
>information, then do the actual personalization and emailing in a batch
>job.
>>
>It also means your user isn't waiting 5 minutes for a response.
>>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attglobal.net
>==================
>
had a similar problem these days.
Is output_buffering set to a default value( output_buffering!=0 )?
You have to output something so that the browser will not close the
connection after HTTP_KEEP_ALIVE (which i belive is 30s by default
anyway). The connection is closed by the browser,not by the server...
>
If output_buffering is set, than you have to send that many bytes, so
the browser actually receives something, so it will not consider the
connection as timed-out.

thanks for the responses.
I'm not clued-up on setting up batch jobs.
I'll check it out.
Output buffering is set to 0, and although I may be able to re-set it I am
ignorant as to its significance!
I dont understand .. 'If output_buffering is set, than you have to send that
many bytes'..

Any other suggestions how I could keep the browser connected for more than
30 secs
while the script is running?
I dont mind if it's a bit clunky as the mailing list is relatively small.

Maybe I could time the mailing for() loop, stop it short of the 30 secs
send something to the browser to keep it interested, restart loop etc.

(I did try something like that, but nothing displayed until the mail loop
had finished anyway
so it didnt work - perhaps it could be 'refined')



--
--------------------------------------------
----THE END of this transmission----
Feb 15 '08 #4

P: n/a
Greetings, This.
In reply to Your message dated Friday, February 15, 2008, 13:43:13,
Are there any techniques for keeping the connection alive while a longish
script executes?
Any suggestions?
Put Your spamming script into CRON and forget about it.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Feb 19 '08 #5

P: n/a
AnrDaemon wrote:
Greetings, This.
In reply to Your message dated Friday, February 15, 2008, 13:43:13,
>Are there any techniques for keeping the connection alive while a longish
script executes?
Any suggestions?

Put Your spamming script into CRON and forget about it.

What makes you think he's spamming? I have several customers who send
out more emails than that at a time. And they're all done by double
opt-in mailing lists.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Feb 19 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.