473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Close http connection but continue execution?

Hi All,

I'm trying to work out how to close the connection to the browser at a
defined point within my code, but go on to do some time-consuming
processing with PHP.

Although it *should* be possible to do this by moving the slow stuff into a
function registered with register_shutdown_function, it appears that in
many cases, the connection is not closed before calling the shutdown
function - there are also issues with calling other functions from the
registered function.

I can't close stdout since I don't have a handle for it.

While I can get the desired result by creating a sort of 'proxy' which posts
on to the real script without waiting for the latter to finish this will be
rather difficult to implement in the operational context.

TIA,

C.
Jul 17 '05 #1
3 6921
Colin McKinnon wrote:
Hi All,

I'm trying to work out how to close the connection to the browser at a
defined point within my code, but go on to do some time-consuming
processing with PHP.


I'm not sure if this is going to be possible for you but I do this sort
of thing with a process daemon.

The initiating script dumps a record into an SQL table to schedule a job
start. I then have a small perl daemon process watching this table for
jobs and then exec's the relevant php process. The php process updates
the current status field in the table as it runs so I can have a script
to display the job queue. I also have space for the offline process to
enter a link into the job queue to collect the process output.
Jul 17 '05 #2
Kevin Thorpe wrote:

The initiating script dumps a record into an SQL table to schedule a job
start. I then have a small perl daemon process watching this table for
jobs and then exec's the relevant php process. The php process updates
the current status field in the table as it runs so I can have a script
to display the job queue. I also have space for the offline process to
enter a link into the job queue to collect the process output.


Yes, I thought about doing that but to get turnaround I require I would need
to poll the queue ever three seconds. Then I have the complication of
locking the requests that are being processed from the queue if I do it via
'cron' and care/feeding of homegrown daemons poses a number of problems
too.

grr.

I guess I could do `at now php -q script.php $params` too - but that
requires me to rewrite a LOT of code.

I've now created a proxy script in PHP which relays POST/GET requests to
another script collects the headers, and any output up until it sees a
specific string in the output then closes the connection and returns the
headers and content to the client. Only problem is that even an explicit
flush() in the backend script doesn't have the desired effect. (no...not
using mod_gzip, nor do I think I'm using anything else which might be
buffering the output in Apache).

Any more suggestions?

C.
Jul 17 '05 #3
Colin McKinnon wrote:

I've now created a proxy script in PHP which relays POST/GET requests to
another script collects the headers, and any output up until it sees a
specific string in the output then closes the connection and returns the
headers and content to the client. Only problem is that even an explicit
flush() in the backend script doesn't have the desired effect. (no...not
using mod_gzip, nor do I think I'm using anything else which might be
buffering the output in Apache).


Solved - added a print "\n"; before flush()

happy me :)
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: MacDermott | last post by:
I have an Access MDB which instantiates a class in a custom DLL, manipulates it for a while, then sets it equal nothing. The MDB does other things,too, and generally behaves itself as desired....
6
by: No_Excuses | last post by:
All, I am interested in reading the text of a web page and parsing it. After searching on this newgroup I decided to use the following: ******************************* START OF CODE...
12
by: MuZZy | last post by:
Hi, Sorry for a repeated post but i didn't receive an answer and will try to re-phrase my question: How do i close an additional thread from the main thread, if this additional thread is stuck...
4
by: Steve Richter | last post by:
I really miss c++ .... I have an SqlConnection object within my Web.UI.Page object. The thinking is that the connection to the database server is opened once when the page starts to do its...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
4
by: mescano | last post by:
I am currently implementing a singleton pattern for accessing a database. Is it advisable to close the connection to the database at all -- thus leaving it open or should it be closed. If closed,...
8
by: Imran Aziz | last post by:
Hello All, Like in C++ I tried to use constructor to open a database connection and distructor to close the database connection, it now turns out that one cannot create distrutors in C# classes. ...
3
by: Tyno Gendo | last post by:
I just wondered if someone could clarify... I have a a script connecting with mysql_connect and in an include at end of page mysql_close If they script terminates before end of page ie. with an...
2
by: boole | last post by:
Hi there, when my ASP page receives the client request, I want to gather the request data (form), promptly end the response to the client (successful) and continue doing what I need to do with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.