473,770 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_shutdo wn_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 6944
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
2690
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. But, if I have done the DLL thing, even though I close the MDB, Access refuses to close. If I haven't used the DLL, all is well. The DLL is one I wrote myself in VB. I'm quite stumped, and rather guess the problem may be in the DLL (I've also
6
4606
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 ************************ String sTemp = "http://cgi3.igl.net/cgi-bin/ladder/teamsql/team_view.cgi?ladd=teamknights&num=238&showall=1"; WebRequest myWebRequest = WebRequest.Create(sTemp); WebResponse myWebResponse = myWebRequest.GetResponse();
12
2138
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 waiting for a blocking operation, eg. if in this additional thread i wait for a Tcp connection: Socket s = tcpListener.AcceptSocket();
4
2057
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 thing, then when everything is rendered down to the browser, and all references to the page object are ended, the connection to the server can be closed. First of all, are the SqlConnection Open and Close methods quick performers and I dont need to...
35
11421
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 Then CType(cn, IDisposable).Dispose() End If I have to admit, I'm not sure what happens here. Will someone explain this line of code (the middle one, not the if statement LOL) to me please?
4
3984
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, when should I it close it -- after the execution of the each command to the database? If leaving open, what impacts does it have. Imagining that it is one connection to the database. Thanks, mescano
8
14571
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. Here is my code public class DBLayer {
3
2044
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 exit() or maybe trigger_error(), does php always disconnect the open'ed connection? I ask because PHP manual says yes, but I've seen some comments relating to PHP 4 saying it doesn't. Please can you tell me your experiences?
2
4185
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 data, the result of which does not affect the response, hence why i don't want to waste time leaving the connection open or keeping the client waiting, I suppose you could call the client request a "trigger". I do not mind using ASP functions...
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.