views:

42

answers:

2

I've spent a while on this but can't get this to work, I apologize as I asked a somewhat related question about this earlier but deleted it so I could do more research to narrow down the question, at this point I am stuck as I thought I had the solution with this but its not working as I expect.. I found a forum where someone asked a similar question and they gave code like below, which I am trying.. it does run the script, but it still waits for it to finish before going to the next line in the PHP code

    proc_close(proc_open ("/var/www/other_scripts/perl/apps/emails_extract_from_url.pl \"$stoopid\"", array(), $foo));
+2  A: 

Hey i've been using proc_open alot lately and it never waits for it to finish before moving on. Make sure you specify the pipes and not just use an empty array()

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

and also assign proc_open to a variable.

$myProc = proc_open("/var/www/other_scripts/perl/apps/emails_extract_from_url.pl \"$stoopid\"", $descriptorspec , $foo)

You can then get the status of your process by using proc_get_status($myProc);

More information here http://au.php.net/proc_open

More Information on closing.

$temp = fgets($this->open_pipes[$thread_id][1], 1024);
if($this->checkFinishedThread($thread_id))
{
    fclose($this->open_pipes[$thread_id][1]);
    proc_close($thread);
}

function checkFinishedThread($thread_id)
{
    $test = stream_get_meta_data($this->open_pipes[$thread_id][1]);
    if($test['eof'] == 1)
        return true;
    return false;
}
ozatomic
Thanks, will check into that.. I was just going by a post where the guy said to do it just like that and it should work, so I will modify it as you suggested
Rick
UPDATE: I have tried exactly what you posted, but it is still waiting for the script it calls to finish, i am finding this bizarre.. I am using PHP with apache (so I'm calling it from a web browser), so I don't know if that would affect it somehow
Rick
hmm, it might. I normally use this when running on the command line. But in saying that i'm sure i've doneit in a browser aswell and it has worked. Can you post the whole script in your post?
ozatomic
ozatomic can you tell what version of php and os you tested it on and it worked? For me it hangs at proc_close for alot of time under ubuntu and centos in command line, apache and lighttpd.
vlad b.
Yeah i've had this happen to me aswell.The way i go around this was to run a check before i close it. I have updated my answer to include the information.
ozatomic
A: 
vlad b.
yeah I had the same issue which was throwing me off as my PHP script actually wasn't waiting, I just thought it was since the perl script that was supposed to finish was still running... it seems that doing a command line kill is a good way to go
Rick
doe() actually does an echo, forgot the function.
vlad b.