2

I use XAMPP 1.7.7 on windows7.(PHP Version 5.3.8) I use proc_open() run a process and want to redirect to another web page, but PHP will wait until the process is finished. I don't want the running process make my web to wait it. What should I do?

And I need pipes and the return value.

What I need: A user submit something in page A,then the web will redirect to page B(and user can leave page B). At the same time some processes will be called , produce some results and update the database,so when the user refresh the page B,the right result will be show. What's more,the user can view the page B any time. I notice that chris's comment on PHP Manual,his method can run a process which is independent with PHP.But I don't know how to use pipes on the hide process or get the return value.

And I have no idea on AJAX,I think the Gearman maybe work,but it's maybe a little complex.

power
  • 45
  • 1
  • 7

4 Answers4

0

PHP is single threaded by design. There is no way to leave a php process running when the HTTP request has finished.

Having said that, you could exploit AJAX to do what you want. Instead of having one HTTP request, fire two requests at the same time. One of them will contain the long process (along with set_time_limit(0)).

There are a lot of different ways to do that. What I usually do is that: When I receive the initial request, I respond immediately with an HTML page that contains an automatic AJAX call to the second php file that contains the long process. So everybody is happy: the user sees immediate response and the long process can take its time as nobody is waiting.

linepogl
  • 9,147
  • 4
  • 34
  • 45
0

This should be done using a job queue like Gearman so that you can leave a worker running and then interrogate it for its status later from the page you redirect to.

To install Gearman on Windows please see this previous SO question and answers: How to configure or install GEARMAN in windows OS?

Community
  • 1
  • 1
Treffynnon
  • 21,365
  • 6
  • 65
  • 98
0

Try seeing if your problem is answered by this: http://nsaunders.wordpress.com/2007/01/12/running-a-background-process-in-php/

Deji
  • 760
  • 1
  • 10
  • 16
  • Sorry,it's not work for me.Because I run a windows OS and I need pipes to transfer data to the process's STDIN and get it's STDOUT,STDERR and get it's return value. – power Feb 11 '12 at 14:59
0

I have solved this by start a new PHP to implements my request. http://www.php.net/manual/en/function.proc-open.php#90584

power
  • 45
  • 1
  • 7