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

Baffling! Redirects with header() takes minutes to respond.

Something odd is happening. Scripts on several sites that collect form
data, save it to a DB, then redirect the user to another page are
slowing to a crawl during the redirect using the header() function. For
example: header("Location:member.php").

I tried changing the header() command in a few ways:
header("Location:/member.php"), header("Location:./member.php"),
header("Location:http://www.site.com/member.php"). But none of these
made any difference.

I then discovered that if I put "exit;" after the header() function,
there's no more delay and the redirect is instantaneous again.

What's odd is that these pages worked just fine without the exit
command until recently. I've made no changes to those scripts, or to
PHP, so, I can't figure out why this all of a sudden started happening.

Has anyone else noticed this? Is putting an "exit;" right after a
header() now required in PHP? Because I never had to do this before and
it always worked fine.

Using PHP 4.3.2 on Linux Red Hat ES 3.0 server. Tested this in Safari,
Firefox and MS IE, with the same (slow) redirect results (until "exit;"
was added).

Monty

Nov 22 '05 #1
7 2857
On 15 Nov 2005 14:02:36 -0800, "Monty" <mo****@hotmail.com> wrote:
Something odd is happening. Scripts on several sites that collect form
data, save it to a DB, then redirect the user to another page are
slowing to a crawl during the redirect using the header() function. For
example: header("Location:member.php").
The HTTP standards prohibit relative URIs in the Location header, so you're
relying on whatever the browser does to compensate for invalid headers.

http://www.w3.org/Protocols/rfc2616/....html#sec14.30
I tried changing the header() command in a few ways:
header("Location:/member.php"), header("Location:./member.php"),
header("Location:http://www.site.com/member.php"). But none of these
made any difference.
The final one is at least valid.
I then discovered that if I put "exit;" after the header() function,
there's no more delay and the redirect is instantaneous again.

What's odd is that these pages worked just fine without the exit
command until recently. I've made no changes to those scripts, or to
PHP, so, I can't figure out why this all of a sudden started happening.

Has anyone else noticed this? Is putting an "exit;" right after a
header() now required in PHP? Because I never had to do this before and
it always worked fine.
It's never been required, but for Location it makes sense; there's not a great
deal of point outputting more content after it.

What code actually runs after the header? Odds are something has changed
there. You mention a database; has a table got considerably larger over time,
resulting in a previously fast query turning into a long-running query running
after the header() call?
Using PHP 4.3.2 on Linux Red Hat ES 3.0 server. Tested this in Safari,
Firefox and MS IE, with the same (slow) redirect results (until "exit;"
was added).


4.3.2 is rather old - 4.3.11 is the latest on that branch, or 4.4.1 for the
latest PHP4. Probably not immediately relevant, but there are a lot of nasty
bugs if you're that far behind, including security issues.
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 22 '05 #2
The PHP version on my server is part of the standard Red Hat Linux ES
3.0 bundle, and is updated by RedHat, so, while the version may be
4.3.2, it has all the fixes and security updates already applied by
RedHat Up2date.

None of the things you mention as a possible cause for this are
relevant, actually, because the fix is to add an "exit;" after a
header. Once I do that, it works as it used to. If the cause was
something else, I presume adding an exit would make no difference, but
it does. As I mentioned previously, I have made no other changes to
this code or PHP before this issue arose, the database table is not
large at all, and even when using a full, non-relative domain in the
header() function, it made no difference at all.

The only thing that did work was to add "exit;" after all
header("Location:...") functions. I checked the online PHP manual, and
there's no mention that this is necessary, so, I am totally baffled as
to why this suddenly started happening.

Nov 22 '05 #3
On 15 Nov 2005 18:35:06 -0800, "Monty" <mo****@hotmail.com> wrote:
The only thing that did work was to add "exit;" after all
header("Location:...") functions. I checked the online PHP manual, and
there's no mention that this is necessary, so, I am totally baffled as
to why this suddenly started happening.


The header("Location:...") function does not terminate your script.
So any processing after the header() will continue. Usually that's
not what you want -- you usually want to exit() at that point.

What does you script do after the header is sent? Chances are, it's
still doing something.

Nov 22 '05 #4
Following on from Monty's message. . .
The only thing that did work was to add "exit;" after all
header("Location:...") functions. I checked the online PHP manual, and
there's no mention that this is necessary, so, I am totally baffled as
to why this suddenly started happening.

Just out of curiosity. What happens if you replace exit; with
print("after header"); ? (I can't say I've ever had this prob 'cos I
always used exit anyway.)

--
PETER FOX Not the same since the bookshop idea was shelved
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Nov 22 '05 #5
On Wed, 16 Nov 2005 10:02:04 +0000, Peter Fox
<pe******@eminent.demon.co.uk.not.this.bit.no.html > wrote:
Following on from Monty's message. . .
The only thing that did work was to add "exit;" after all
header("Location:...") functions. I checked the online PHP manual, and
there's no mention that this is necessary, so, I am totally baffled as
to why this suddenly started happening.

Just out of curiosity. What happens if you replace exit; with
print("after header"); ? (I can't say I've ever had this prob 'cos I
always used exit anyway.)


You shouldn't see anything. You'll end up transmitting "after header"
to the browser but it'll see the location header and redirect anyway.

Nov 22 '05 #6
On 15 Nov 2005 18:35:06 -0800, "Monty" <mo****@hotmail.com> wrote:
The PHP version on my server is part of the standard Red Hat Linux ES
3.0 bundle, and is updated by RedHat, so, while the version may be
4.3.2, it has all the fixes and security updates already applied by
RedHat Up2date.
Ah. Fair enough.
None of the things you mention as a possible cause for this are
relevant, actually, because the fix is to add an "exit;" after a
header. Once I do that, it works as it used to. If the cause was
something else, I presume adding an exit would make no difference, but
it does.


I'm suggesting that some of your code that is running after the header() call
that is taking a significant time.

Adding exit immediately after header() prevents that code running.

For a trivial example:

<?php
header("Location: http://www.php.net/");
sleep(10);
?>

This takes 10 seconds to actually redirect. So the code that runs after
header() is significant. exit skips it. If it worked before, then surely it is
a possible cause that the code used to run quickly so you didn't notice, but
now it runs slowly.

So, what is running after the header call?
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 22 '05 #7
> So, what is running after the header call?

Hi. The only code that would be executed after the header() call is to
load a record from the DB to display it in the form. That's it. When I
remove the header() call completely (allowing the page to reload), it
happens instantly, so, I don't think the code that follows is causing
the delay. But, if I put the header() call back in without an exit, it
takes hangs for minutes before moving forward.

And the odd thing is that this never happened before, and I didn't make
any changes at all to these scripts that are all of sudden hanging at a
header() call if not followed by exit. But, it's also not ALL header()
calls doing this. On some pages without an exit, it happens just as
fast as when I add the exit, so, the results seem to be very
inconsistent.

I guess no one else has been having this problem. Very strange!

Nov 22 '05 #8

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

Similar topics

1
by: Ben Floyd | last post by:
It goes like this: Im converting a perl script that executes a command on each result of a directory listing. In perl, all is well. In Python, using approximately the same logic creates a...
2
by: ghasem | last post by:
Dear mySQL community, I have once again turned to the user groups for a problem I cannot solve myself! Atually, I have read all I can from the newsgroups on this but I could not solve it myself....
4
by: MAB71 | last post by:
I'm running an ISP database in SQL 6.5 which has a table 'calls'. When the new month starts I create a new table with the same fields and move the data of previous month into that table and delete...
12
by: Mike | last post by:
I have posted this before, but no one responds, so here it goes again. I think my question is intimidating people and I have no idea why?!? This is not a new concept. You can do this with other...
10
by: Amelyan | last post by:
It takes VS 2005 1, 2, and somtimes 3 MINUTES to compile ASP.NET 2.0 website when external DLL is modified. As a matter of fact, when I click 'Build', it looks like VS 2005 hangs for most of that...
7
by: hazz | last post by:
What happens if I set the timer interval for a period that is less than the time it will take to process the loop below? Right now my application is returning just a few items in an arraylist to...
1
by: Rick Sypriano | last post by:
Hello, I have a WebService that uses ADO.net to update a SQL database on a remote server. If the database operation takes less than 4 minutes everything works fine. If the database operation...
2
by: Martin Eckart | last post by:
Hello, I have built a Hello World Web Service using Visual Studio 2005 and .NET 2.0 on machine A. Setting up a Web Site on machine B and adding a web reference to that WS works fine, without any...
0
by: DR | last post by:
PerformanceCounterCategory.Create() takes 3 minutes to add a new category!! If I run PerformanceCounterCategory.Create() on my development machine it only takes a few seconds. But on remotely...
8
by: jr | last post by:
I have an application the makes a call to a webservice to retrieve some additional info for my app. The information I get back is non-essential, so I do NOT want my entire app hanging to wait for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.