-2

I have two exec() function with timeout argument. eg:

<?php
exec("timeout 5 /usr/local/bin/trun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$t_uptime);
exec("timeout 5 /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$t_uptime);
?>

Isn't working. I want exec() stop after 5 sec and next exec() function starts its execution. Please correct this or give some alternative way to stop exec() function

nanobash
  • 5,419
  • 7
  • 38
  • 56
Tomas
  • 514
  • 4
  • 13
  • 37

2 Answers2

0

exec — Execute an external program

string exec ( string $command [, array &$output [, int &$return_var ]] )

exec() executes the given command.
ankit singh
  • 367
  • 1
  • 3
  • 13
0

use this function instead- for more info read http://in2.php.net/function.exec

 function PsExecute($command, $timeout = 5, $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;
            if( !PsExists($pid) )
                return true; // Process must have exited, success!
        }

        // If process is still running after timeout, kill the process and return false
        PsKill($pid);
        return false;
    }
sunny
  • 1,156
  • 8
  • 15