I recently made a Dongdong, the general framework is:
The visitor submits the C program through the Web, the server invokes the compiler compile and runs the compiled program after the compilation completes, and returns the results of the run back to the visitor's browser.
And regardless of security, because the visitor can be believed to be trustworthy, the command-line compiler will eventually return, but for a program that is temporarily compiled, although the user is trustworthy, but does not rule out deadlocks due to imperfections, the process that started after the PHP call fails to return and times out, and the process persists until the server restarts , as time passes, server-side resources will be depleted.
Considering that PHP itself does not provide multithreading and process management functions (perhaps I do not see this information), the use of either exec, or Popen, the main program once blocked can not extricate themselves, Therefore, a thread must be reserved to manage the initiated process if necessary. And I don't want to make changes to the server configuration. So think of yourself to write a program management startup process, PHP indirectly through this program to invoke the compiled client program, to achieve the client program timeout control.
Here is the test PHP program.
?
filename:test1.php
$cmd = "Test.exe 154";//input your command here
$cmd = "Process.exe 5000". $cmd;
$descriptorspec = Array (
0 => Array ("Pipe", "R"),//stdin is a pipe this child would read from
1 => Array ("Pipe", "w"),//stdout is a pipe which the child would write to
2 => Array ("File", "Error-output.txt", "w+"),//stderr is a file to write to
);
$process = Proc_open ($cmd, $descriptorspec, $pipes);
if (Is_resource ($process)) {
$pipes now looks like this:
0 => writeable handle connected to child stdin
1 => readable handle connected to child stdout
Any error output'll be appended to/tmp/error-output.txt
Fwrite ($pipes [0], ' 12345678 ');/input integer to scanf, and you should add ' \ n ' at the end of string as ' Ente R ';
Fclose ($pipes [0]);
while (!feof ($pipes [1])) {
Echo nl2br (Fgets ($pipes [1], 1024));
}
Fclose ($pipes [1]);
It is important so close any pipes before calling
Proc_close in order to avoid a deadlock
Proc_terminate ($process);
$return _value = Proc_close ($process);
echo "<br>command returned $return _value\n";
}
?>
Process.exe is the agent program that I write to PHP.