How to check in CGI if client disconnected | | |
Hi,
I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.
Is there any way to do this? Any help on this is appreciated :)
Regards,
-vishal. | | | | re: How to check in CGI if client disconnected
En Sun, 24 Aug 2008 14:25:03 -0300, Vishal <vrshah@gmail.comescribió: Quote:
I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.
>
Is there any way to do this? Any help on this is appreciated :)
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
--
Gabriel Genellina | | | | re: How to check in CGI if client disconnected
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote: Quote: Quote:
> I am writing a CGI to serve files to the caller. I was wondering if
>there is any way to tell in my CGI if the client browser is still
>connected. If it is not, i want to execute some special code before
>exiting.
>>
> Is there any way to do this? Any help on this is appreciated :)
>
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
--
Regards,
Wojtek Walczak, http://tosh.pl/gminick/ | | | | re: How to check in CGI if client disconnected
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gminick@bzt.bztescribió: Quote:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote: Quote: Quote:
>> I am writing a CGI to serve files to the caller. I was wondering if
>>there is any way to tell in my CGI if the client browser is still
>>connected. If it is not, i want to execute some special code before
>>exiting.
>>>
>> Is there any way to do this? Any help on this is appreciated :)
>>
>I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
>
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.
--
Gabriel Genellina | | | | re: How to check in CGI if client disconnected
Hi,
Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?
I tried using the signal module
---
def sigtermHandler(signum, frame):
# do some cleanup
signal.signal(signal.SIGTERM, sigtermHandler)
---
But even this doesn't work.
Regards,
-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote: Quote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
> Quote:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote: Quote:
>* *I am writing a CGI to serve files to the caller. I was wondering if
>there is any way to tell in my CGI if the client browser is still
>connected. If it is not, i want to execute some special code before
>exiting.
> Quote: Quote:
>* *Is there any way to do this? Any help on this is appreciated :)
> Quote: Quote:
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
> Quote:
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
>
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, readsits parameters, do its task, and exits. There is no "long running process"in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
>
If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.
>
--
Gabriel Genellina
| | | | re: How to check in CGI if client disconnected
On Aug 25, 4:26*pm, Vishal <vrs...@gmail.comwrote: Quote:
Hi,
>
* Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?
>
I tried using the signal module
>
---
def sigtermHandler(signum, frame):
* * # do some cleanup
>
signal.signal(signal.SIGTERM, sigtermHandler)
>
---
>
But even this doesn't work.
Have you considered simply checking to see if the amount of POST
content read matches the inbound Content-Length specified in the CGI
environment. If your processing of POST content finds less than what
was meant to be sent, then likely that the client browser aborted
request before all content could be sent.
Graham Quote:
Regards,
>
-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> Quote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
> Quote: Quote:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>>* *I am writing a CGI to serve files to the caller. I was wondering if
>>there is any way to tell in my CGI if the client browser is still
>>connected. If it is not, i want to execute some special code before
>>exiting.
> Quote: Quote:
>>* *Is there any way to do this? Any help on this is appreciated:)
> Quote: Quote:
>I don't think so. A CGI script runs once per request, and exits. Theserver may find that client disconnected, but that may happen after the script finished.
> Quote: Quote:
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
> Quote:
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
> Quote:
If processing takes so much time, it's better to assign it a "ticket" -the user may come back later and see if its "ticket" has been finished, orthe system may send an email telling him.
> Quote:
--
Gabriel Genellina
| | | | re: How to check in CGI if client disconnected
Hi Graham,
Thanks for the reply. In my case, it's the other way round. I need
to check if the amount of data sent is equal to the file size i want
to send. However, the question is - when do i check this? Currently, i
am unable to call any cleanup code before exit.
Regards,
-vishal.
On Aug 25, 11:44*am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote: Quote:
On Aug 25, 4:26*pm, Vishal <vrs...@gmail.comwrote:
>
>
> > Quote:
* Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?
> Quote:
I tried using the signal module
> Quote:
---
def sigtermHandler(signum, frame):
* * # do some cleanup
> Quote:
signal.signal(signal.SIGTERM, sigtermHandler)
> > Quote:
But even this doesn't work.
>
Have you considered simply checking to see if the amount of POST
content read matches the inbound Content-Length specified in the CGI
environment. If your processing of POST content finds less than what
was meant to be sent, then likely that the client browser aborted
request before all content could be sent.
>
Graham
> > Quote:
-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> Quote: Quote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
> Quote: Quote:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>* *I am writing a CGI to serve files to the caller. I was wondering if
>there is any way to tell in my CGI if the client browser is still
>connected. If it is not, i want to execute some special code before
>exiting.
> Quote: Quote:
>* *Is there any way to do this? Any help on this is appreciated :)
> Quote: Quote:
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
> Quote: Quote:
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
> Quote: Quote:
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
> Quote: Quote:
If processing takes so much time, it's better to assign it a "ticket"- the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.
> Quote: Quote:
--
Gabriel Genellina
>
>
| | | | re: How to check in CGI if client disconnected
On Aug 25, 5:49*pm, Vishal <vrs...@gmail.comwrote: Quote:
Hi Graham,
>
* *Thanks for the reply. In my case, it's the other way round. I need
to check if the amount of data sent is equal to the file size i want
to send. However, the question is - when do i check this? Currently, i
am unable to call any cleanup code before exit.
Best you will do for writing, is to catch exceptions around the call
outputing the data. If an exception occurs then a problem has
obviously occurred.
Graham Quote:
Regards,
>
-vishal.
>
On Aug 25, 11:44*am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
> Quote:
On Aug 25, 4:26*pm, Vishal <vrs...@gmail.comwrote:
> > Quote: Quote:
* Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?
> Quote: Quote:
I tried using the signal module
> Quote: Quote:
---
def sigtermHandler(signum, frame):
* * # do some cleanup
> Quote: Quote:
signal.signal(signal.SIGTERM, sigtermHandler)
> > Quote: Quote:
But even this doesn't work.
> Quote:
Have you considered simply checking to see if the amount of POST
content read matches the inbound Content-Length specified in the CGI
environment. If your processing of POST content finds less than what
was meant to be sent, then likely that the client browser aborted
request before all content could be sent.
> > > Quote: Quote:
-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> Quote: Quote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
> Quote: Quote:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>>* *I am writing a CGI to serve files to the caller. I was wondering if
>>there is any way to tell in my CGI if the client browser is still
>>connected. If it is not, i want to execute some special code before
>>exiting.
> Quote: Quote:
>>* *Is there any way to do this? Any help on this is appreciated :)
> Quote: Quote:
>I don't think so. A CGI script runs once per request, and exits.The server may find that client disconnected, but that may happen after the script finished.
> Quote: Quote:
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
> Quote: Quote:
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts,reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
> Quote: Quote:
If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.
> Quote: Quote:
--
Gabriel Genellina
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|