Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have five exec() functions in my script. I want to set it up so that if a function fails to respond in a given time, the function will be killed and the next function will start its execution.

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

In this the timeout argument is not working. Please correct this or give me an alternative method.

share|improve this question

your exec sysntax is wrong

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

You have to set time limit before you begin your code, something like this

<?php

set_time_limit(5);

exec(" /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
?>
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .