Re: connection drops while script running



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 <info@xxxxxxxxxxxxxxxx>
wrote:

----- Original Message -----
From: "_q_u_a_m_i_s's" <quamis@xxxxxxxxx>
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...@xxxxxxxxxxxxx> wrote:
>> 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...@xxxxxxxxxxxxx
>> ==================
>
> 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----
.



Relevant Pages

  • Re: Problem in opening websites
    ... msg is "there was no XML in the response". ... the browser gets timed out (the msg is "The connection ... to the server was reset while the page was loading."). ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Choosing whitch button will act as submit button
    ... Use the script exactly as supplied for the browser. ... server-code cannot decide whitch button should be the submit button. ... one server side form tag, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Intermitant XP Network Problems
    ... I have a Win2K domain server that 2 XP Pro PC's log into. ... and can see each other while brosing the network. ... it will lose it's connection again some time in the future ... Browser issues can be caused by many thing, ...
    (microsoft.public.windowsxp.network_web)
  • Re: Got TCP/IP connection, but no file sharing!?
    ... No where can I find that having the Computer Browser Service ... and the server announces itself on the networking using the special ... and why doesn't a workgroup environment work the same ... server) generally acts as the master browser. ...
    (microsoft.public.windowsxp.network_web)
  • Re: different behavior - localserver vs prod server
    ... But I don't understand what you mean when you say to type the src urls ... into the browser to see if they are correct. ... > Smart Navigation and Client Range checking are implemented by client script, ... and how it behaves on the server. ...
    (microsoft.public.dotnet.framework.aspnet)