0

Is it possible to do an http direct when the child process of a fork has returned to the parent?

I tried doing:

header("Location: http://dev.mysite.com/invokefork.php?semaphoreid=".$semaphoreid."/");

This resulted in the error below, which is strange because there is nothing being echoed out when I'm running fork.php from the terminal. This script is normally run by a call to exec() within invokefork.php

PHP Warning:  Cannot modify header information - headers already sent

Obviously I can't do an http redirect from the command line, I just wanted to see what would happen. When I tried running invokefork.php from the browser it didn't do the redirect. The warning is present at the same line that the header() call is on.

What want to do is have a background process which takes params and performs a search. While the search is being performed I'm thinking of redirecting to a "searching" page which checks the semaphore every 30 secs to see if it has been populated with data.

This should help understand a little more:

    $pid = pcntl_fork(); 
    if ($pid == -1) { 
       die("could not fork"); 
    } elseif ($pid) { 
        pcntl_waitpid($pid, $status, WUNTRACED);

    } else { 
        // emulate db/web service query.  
        sleep(10);

        /*
            Do webservice / database query here
            When results return add them to shared memory
            Redirect and pass semaphore id to so the data
            from the semaphore can be looked up.
        */

       header("Location: http://dev.globalgatewaydemo.com/invokefork.php?pid=".$pid."/");

    } 

Any ideas?

user1532669
  • 2,288
  • 4
  • 36
  • 72
  • Yes, wouldn't work in a CLI script anyway. But why/how/what are you forking a PHP process in the first place? That would severe the F/CGI pipe to the webserver for most SAPIs anyway. Explain that more exactly. -- As for the error: [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/q/8028957) - check warning details (file+line no) yourself. – mario Aug 29 '15 at 21:19
  • 1
    possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – RiggsFolly Aug 29 '15 at 21:21
  • @mario I've added some further detail, hope this makes a bit more sense :) – user1532669 Aug 29 '15 at 21:52

0 Answers0