+
95
-

PHP exec执行外部程序如何超时自动关闭杀死外部程序?

php

PHP exec执行外部程序如何超时自动关闭杀死外部程序?

网友回复

+
15
-

<?php 
function PsExecute($command, $timeout = 60, $sleep = 2) { 
    // First, execute the process, get the process ID 

    $pid = PsExec($command); 

    if( $pid === false ) 
        return false; 

    $cur = 0; 
    // Second, loop for $timeout seconds checking if process is running 
    while( $cur < $timeout ) { 
        sleep($sleep); 
        $cur += $sleep; 
        // If process is no longer running, return true; 

       echo "\n ---- $cur ...

点击查看剩余70%

我知道答案,我要回答