473,386 Members | 1,803 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,386 software developers and data experts.

Closing an HTTP connection

Hi,

I need some help here.

Is it possible to close an HTTP connection in the middle of a php
script?

For example:

<html>
<body>
This is a web page
</body>
</html>
<?php
shell_exec("program");
?>
I know that the shell_exec statement will take a long time to complete.
But I also know that no further content needs to be delivered to the
user. Is it possible to close the connection so that the browser is not
hanging around waiting for more information, but the php script keeps
running on the server?

Thanks for any help.

Aug 29 '05 #1
3 1998
>From http://www.php.net/manual/en/function.exec.php

"Note: If you start a program using this function and want to leave it
running in the background, you have to make sure that the output of
that program is redirected to a file or some other output stream or
else PHP will hang until the execution of the program ends."

Aug 29 '05 #2
Also, the very first comment here:
<http://www.php.net/manual/en/function.shell-exec.php> explains how to
do this with shell_exec()

Aug 29 '05 #3
ZeldorBlat wrote:
From http://www.php.net/manual/en/function.exec.php
"Note: If you start a program using this function and want to leave it
running in the background, you have to make sure that the output of
that program is redirected to a file or some other output stream or
else PHP will hang until the execution of the program ends."


Won't work - you haven't dissocciated the new process from the parent.
(Might work on a non-unix system). The webserver won't send an EOF until
the chid process terminates. You could call it from a function registered
using register_shutdown_function() to run after the socket is closed but
that's still messy as the the webserver process hangs around to wait for it
to exit.

You can create a separate process group easily using the 'at' command.

$run_in_background=`echo $name_of_script | at now`;

Chris wrote:
Is it possible to close an HTTP connection in the middle of a php
script?


If the above didn't answer your question (there are instances where you
might want to disconnect from the browser but continue with the current
thread of execution) then repost - there's an answer to this as well, but
it really starts getting complicated and you need to start working with
proxy scripts and sockets.

C.

Aug 29 '05 #4

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

Similar topics

4
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to...
0
by: ajaykrishna | last post by:
Hi Could any one tell me what is the latest version of System.Data.OracleClient? Currently I'm using version 1.0.1012.0 in my project which is giving problem of not closing connection eventough...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
13
by: Simon Harvey | last post by:
Hi All, I have a colleague that I wprk with that develops using ASP. I develop using ASP.net. He seems to make sites much faster than me and I am wondering if its because of the two different...
3
by: Paolo Pignatelli | last post by:
I have a Function in a Class File that uses ApplicationBlocks: Public Function GetProductsByCategory(ByVal CategoryID As Integer) Dim myConnection As SqlConnection = New...
5
by: Daves | last post by:
is it a good or bad practise to use the session_start & session_end for opening & closing the database connection? I'd thought that on powerful servers today the time the connection is kept locked...
7
by: Tumurbaatar S. | last post by:
Is it so important to close database connections? As I understand, after processing a request and sending a response, page object destroyed. So all used connections also destroyed. Yes?
3
by: rockdale | last post by:
I am using Microsoft.Practices.Enterprise.Library When I use IDataReader I saw this line "It is the responsibility of the caller to close the connection and reader when finished." I was...
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
5
by: zacks | last post by:
If I close and dispose an ODBCConnection object, shouldn't the connection actually close? I have found that even after closing and disposing an ODBCConnection, the database it was connected to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.