PHP not closing process on Windows -problem with proc_close?

I am running PHP/MySQL using Xampp/Apache and testing on different windows machines running XP SP2.

On one machine in particular I am having a problem executing an external executable. I have tried using exec, shell_exec, system, exec and passthru, but in each case the system runs the command and then hangs and doesn’t proceed to the next line of code.

The command executed is as follows:
“C:\xampp\htdocs\formatdb.exe” -p F -i inputfile
Where formatdb.exe is an executable for formatting a genomics database and inputfile is the database.

I started using the following code to dissect the problem:

function CmdExec($cmd, &$stdout, &$stderr, $wd)
    $outfile = tempnam(".", "cmd");
    $errfile = tempnam(".", "cmd");
    $descriptorspec = array(
        0 => array("pipe", "r"),
        1 => array("file", $outfile, "w"),
        2 => array("file", $errfile, "w")
    $proc = proc_open($cmd, $descriptorspec, $pipes, $wd);
    if (!is_resource($proc)) return 255;

    fclose($pipes[0]);    //Don't really want to give any input
    $exit = proc_close($proc);
    $stdout = file($outfile);
    $stderr = file($errfile);

    return $exit;

I then ran a logger script to see which line it hangs on.
proc_open does return a resource, and then fclose succeeds in closing the file pointer.
proc_close, on the other hand, fails to close and the system hangs on this line.

I was thinking it might have something to do with the file size - the input is 128MB and the output creates several files that are all pretty big. But it’s running the program, just not closing.

On other machines running seemingly the same operating system this is not a problem - so I am really stumped!

Any help would be appreciated,


I’m not sure what your error_reporting is set to, but try using the following line at the top of your PHP code:


Btw, if you open the task manager, does the process formatdb.exe show up?

Sponsor our Newsletter | Privacy Policy | Terms of Service