1

I have five exec() function in my script.I want if any function will not give any response in given time function will kill and then next function starts 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 timeout argument not working.Please correct this or gives any alternative method.

Tomas
  • 514
  • 4
  • 13
  • 37
  • 2
    `timeout` sends a `term` signal: If the process won't respondi to a term, you can send a `kill` signal instead using `timeout -k 5 /usr...`. – Mark Baker Mar 24 '14 at 08:19
  • @MarkBaker I want kill command automatically send to server if `exec()` not respond in give time. – Tomas Mar 24 '14 at 08:24

1 Answers1

1

Create a bash script caller.sh and execute it via exec. The command will be automatically killed after 5 seconds.

caller.sh

#!/bin/sh
/usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat' &
sleep 5
kill $! 2>/dev/null && echo "Killed command on time out"

PHP

exec("caller.sh",$uptime);
Harikrishnan
  • 9,688
  • 11
  • 84
  • 127