简体   繁体   中英

PHP stream_select doesnt work

I'm using Windows 7 and php 5.

I have a problem with executing a process by proc_open and check the timeout. I used stream_select to check the timeout with this code:

<?php
$descriptorspec = array(
0 => array("file", $infile, "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("pipe", "w") // stderr is a file to write to
);
$prog = @proc_open ($objname.".exe", $descriptorspec, $pipes, "$DOCUMENT_ROOT/judge/temp", null, null);
if(!is_resource($prog)) ErrorResult("","proc_open err");

$streams = array($pipes[1]);
$start = microtime(true);
$ret = stream_select($streams, $a = null,$a = null, 1);
$stop = microtime(true);
?>

This is the C++ code I used to test that:

#include<windows.h>

int main(){
    Sleep(2000);
    return 0;
}

In that code, there's no output at all, but stream_select doesn't wait 1 sec and return 1.

How can i fix this?

I suspect that your C++ executable might not be really executed for some reason, but that the exit code could be hidden from you by cmd.exe .

  • Get a proof that the C++ executable actually runs at all. Attempt to pass some data from C++ to PHP already before calling stream_select .

  • Get cmd.exe out of your way:

    $opts = array('suppress_errors' => false, 'bypass_shell' => true);

    $prog = proc_open ($objname.".exe", $descriptorspec, $pipes, "$DOCUMENT_ROOT/judge/temp", null, null, $opts);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM