Re: Question about apache-php concurrent process control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, July 21, 2005 8:40 pm, Liang ZHONG said:
> I now encounter a problem with flow control of my program with PHP. This
> is
> very crucial to the design of a pretty big project. This is what I want to
> do in the program:
>
> <?php
> do_A();
> header("Location: ".$result_of_do_A);

Depending on the buffering options in php.ini and/or Apache, this may or
may not just end your program, as I understand it.

Once you send the Location header, everything else is irrelevant, or at
least not reliable.

You could do:
echo $result_of_do_A;
flush();

and the user will see what happened with A, while waiting for B.

> do_B();
> ?>
>
> Since it takes do_B()  quite a while to finish, so I want the http client
> get the partial result from do_A() by redirect a page to them before start
> do_B(). But it seems that the redirection will only occure after the
> entire
> php program finishes, i.e., after do_B(). I sent http request through
> browser, curl comman line with -N (no buffer) option and with a perl LWP
> program I wrote. All of them suggest that header(), although is put before
> do_B() in code, gets executed only after all the php code finished. I add
> flush() after header() too, but no work.

If that is what you are seeing happen, you probably have output buffering
turned "on"

The Location: header is acted upon by the BROWSER, not by PHP, not by your
server.  The BROWSER sees that header and then jumps to somewhere else.

> My question is: Is there any way that I can return to the client though
> http
> response and then continue my progress with my program?

You could also look into the pcntl stuff to fork() or, depending on
various settings, you might get:
exec("do_B() &");

to get B to happen in the background.

With all that said:  As a general rule, when I found myself doing this
kind of stuff, I later realized that I hadn't really designed my
application very well for an end-user experience.

If it takes THAT long to finish B, then you're probably MUCH better off
putting something in a "ToDo List" in your database, and doing B "later"
in a cron job.

Then notify the user through email or some kind of status display that
they will see on your site frequently when "B is done"

NEVER make the user sit around waiting for your server.  Human time is far
far far too precious (and expensive!) to waste it sitting around doing
nothing useful waiting for your program to finish.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux