473,625 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"header" call doesn't work before lenghty operation

a
Hi everybody,

My config: Win XP (or 2003), Apache 2.0.54, PHP 5.1.2.

I have been trying to handle the case of a lenghty opearation on the server
while providing the user with feedback and ability to cancel, and nothing
seems to work so far.

The following code is one attempt to address this, and it is called as
result of a POST:

//*************st art code*********** ****
session_start;

// prepare exec

// flush session data
session_write_c lose;

// trying to display a "Please wait..." message:
header( "Location: please_wait.php " );

// long exec
exec( ... );

// finally show the result of the exec
header( "Location: exec_result.php " );
//************end code*********** ********

What happens is that only the last header statement has a visual effect, the
first one doesn't do anything, so the user is not presented with the "Please
wait message".

I would appreciate any ideas or code examples on this or the issue of
handling this sort of lengthy operations in general.

Thanks,

A
Feb 18 '06 #1
16 2907

"a" <xx*****@pacbel l.net> wrote in message
news:ss******** *********@newss vr27.news.prodi gy.net...
Hi everybody,

My config: Win XP (or 2003), Apache 2.0.54, PHP 5.1.2.

I have been trying to handle the case of a lenghty opearation on the
server while providing the user with feedback and ability to cancel, and
nothing seems to work so far.

The following code is one attempt to address this, and it is called as
result of a POST:

//*************st art code*********** ****
session_start;

// prepare exec

// flush session data
session_write_c lose;

// trying to display a "Please wait..." message:
header( "Location: please_wait.php " );
Location should be followed immediately by exit, at least according to the
documentation. it is supposed to transfer you to a new URL. your long exec
and other header should be in your please wait page, but the header cannot
be, because header() only works at the top of the document before any HTML
is output and before any blank lines (I wouldn't even trust whitespace) are
seen. after all your headers are output, then output a blank line to show
end of headers and then your HTML. sorry. you only get one header() per
page.


// long exec
exec( ... );

// finally show the result of the exec
header( "Location: exec_result.php " );
//************end code*********** ********

What happens is that only the last header statement has a visual effect,
the first one doesn't do anything, so the user is not presented with the
"Please wait message".

I would appreciate any ideas or code examples on this or the issue of
handling this sort of lengthy operations in general.

Thanks,

A

Feb 18 '06 #2
a
Thanks for your reply.

Location should be followed immediately by exit, at least according to the
documentation. it is supposed to transfer you to a new URL. your long
exec and other header should be in your please wait page, but the header
cannot be, because header() only works at the top of the document before
any HTML is output and before any blank lines (I wouldn't even trust
whitespace) are seen. after all your headers are output, then output a
blank line to show end of headers and then your HTML. sorry. you only get
one header() per page.


Here is a new attempt, but I still don't see the Please Wait page, instead
it goes straight to the show_result.php

//*********** the form processing.php code*********** *

// long exec (asynchronous - it exits immediately but continues processing),
its end will tested in the next script
exec( ... );

header( "Location: please_wait.php " );

echo( "\nPlease wait" );

flush;
exit;
*********** end of form processing

//********** the "please wait.php" code *************
while( long_operation_ not_done )
usleep( 100000 ); // check the operation each 0.1 secs

header( "Location: show_result.php " );

exit;
//************ end code *************** **

If I put the echo in second php script, I get an error about headers already
sent or similiar.

I don't know php well enough to figure out a solution to unblock me at this
point, so any new idea would be highly appreciated.

A
Feb 18 '06 #3
a wrote:
Here is a new attempt, but I still don't see the Please Wait page,
instead it goes straight to the show_result.php

You could try something as follows instead:

<?php

if (isset($_GET['pause'])) {
sleep(10);
print 'Done';
exit;
}

print 'Please wait';
header("Refresh : 1;url={$_SERVER['PHP_SELF']}?pause=1");

?>
flush;
exit;


flush();
exit;

(flush() is a function and should be called with parenthesis, while exit is
a language construct where the parenthesis indeed can be omitted).
JW
Feb 18 '06 #4
Janwillem Borleffs wrote:
a wrote:
Here is a new attempt, but I still don't see the Please Wait page,
instead it goes straight to the show_result.php

You could try something as follows instead:

<?php

if (isset($_GET['pause'])) {
sleep(10);
print 'Done';
exit;
}

print 'Please wait';
header("Refresh : 1;url={$_SERVER['PHP_SELF']}?pause=1");

?>
flush;
exit;

flush();
exit;

(flush() is a function and should be called with parenthesis, while exit is
a language construct where the parenthesis indeed can be omitted).
JW


Won't work. You can't send a header call after ANY output.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 18 '06 #5
a wrote:
Thanks for your reply.
Location should be followed immediately by exit, at least according to the
documentation . it is supposed to transfer you to a new URL. your long
exec and other header should be in your please wait page, but the header
cannot be, because header() only works at the top of the document before
any HTML is output and before any blank lines (I wouldn't even trust
whitespace) are seen. after all your headers are output, then output a
blank line to show end of headers and then your HTML. sorry. you only get
one header() per page.

Here is a new attempt, but I still don't see the Please Wait page, instead
it goes straight to the show_result.php

//*********** the form processing.php code*********** *

// long exec (asynchronous - it exits immediately but continues processing),
its end will tested in the next script
exec( ... );

header( "Location: please_wait.php " );

echo( "\nPlease wait" );

flush;
exit;
*********** end of form processing

//********** the "please wait.php" code *************
while( long_operation_ not_done )
usleep( 100000 ); // check the operation each 0.1 secs

header( "Location: show_result.php " );

exit;
//************ end code *************** **

If I put the echo in second php script, I get an error about headers already
sent or similiar.

I don't know php well enough to figure out a solution to unblock me at this
point, so any new idea would be highly appreciated.

A


I don't think that's going to be very successful, either. You can't
predict what the browser will do as for caching, for instance.

Maybe flash would work?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 18 '06 #6
Jerry Stuckle wrote:
Won't work. You can't send a header call after ANY output.


Dude, don't judge before trying.
JW
Feb 18 '06 #7
Janwillem Borleffs wrote:
Jerry Stuckle wrote:
Won't work. You can't send a header call after ANY output.

Dude, don't judge before trying.
JW


First of all, I am not your "Dude". And I don't appreciate your
patronizing attitude.

I suggest you learn a few manners. I've probably been doing PHP longer
than you have - and been programming longer than you've been alive.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 18 '06 #8
Jerry Stuckle wrote:
I suggest you learn a few manners. I've probably been doing PHP
longer than you have - and been programming longer than you've been
alive.


You are making assumptions again...
JW
Feb 18 '06 #9
Janwillem Borleffs wrote:
Jerry Stuckle wrote:
I suggest you learn a few manners. I've probably been doing PHP
longer than you have - and been programming longer than you've been
alive.

You are making assumptions again...
JW


I very much doubt it.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 18 '06 #10

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

Similar topics

7
4000
by: Kornelius Finkenbein | last post by:
Hello folks! I've got a strange problem with my download-script in conjunction with M$ internet explorer, if the filename I want to link to includes more than one points. In Netscape the problem doesn't exist. For example: input: ... download.php?name=virtualdub_1.4.9.zip
1
3131
by: Danny Anderson | last post by:
Hola, PHP folk! I have a php page that contains a self-processing form. The form holds search results. The search terms originally came from the previous page, but the user can repeatedly refine the results on the page in question until the target item can be found. This search refinement is where the self-processing form comes to play. The search results are listed in a table with a radio button at the end of each row. What I...
7
25573
by: beliavsky | last post by:
Ideally, one can use someone's C++ code by just looking at the header files (which should contain comments describing the functions in addition to function definitions), without access to the full source code. Can analogs of C++ header files be created for Python code? Python "header" files could list only the 'def' statements and docstrings of Python functions and classes, but that does not tell you what the functions return. One could...
4
2247
by: John Smith | last post by:
I have a project that consists of about a dozen translation units. I use a command line compiler and it occured to me that I could simplify compiling the project by #include(ing) them in a header that looks something like this: /* project.h */ #include "aaa.c" #include "bbb.c" #include "ccc.c" ....
23
3624
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target page I don't get any session variable values! BTW, I used a relative location in the Location header, not an absolute URL. The behavior looks like it started another session, but it should not have. Ideas? TIA,
21
21257
by: cman | last post by:
does anyone know why i can't generate images with: header("Content-type:image/jpeg"); imagejpeg($img_number); i've tried different examples but i always get a text output as if the header doesn't make a difference at all. <?php //random_number.php $img_number = imagecreate(100,50);
28
2242
by: fred.haab | last post by:
Not having server side scripting, I've been doing this for "last modified" tags on my pages: <div class="modified"> <script type="Text/JavaScript"> <!-- document.write("This page was last modified: " + document.lastModified); --> </script>
17
4231
by: StevePBurgess | last post by:
A really simple script is driving me up the wall. I have a very simply facility on a website to allow the user to reorder items in a database table as she wishes by clicking a link that (in this case) says "MOVE UP" and links to the script below. This script snippet that does all the work is shown - the database connection is established and after doing its work the script returns the user to the referring page.
45
9080
by: Umesh | last post by:
please help. thanks.
0
8256
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
8694
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
8635
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
8356
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
8497
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
7184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4089
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...
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1500
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.