exec() with timeout

I’ve searched a bit on this topic and came to conclusion that in some case (if you are using linux) you can use ‘timeout’ command. It’s pretty flexible

Usage: timeout [OPTION] DURATION COMMAND [ARG]...
  or:  timeout [OPTION]

in my particular case I’m trying to run sphinx indexer from PHP, kinda migration data script so I need to reindex my sphinx documents

exec("timeout {$time} indexer --rotate --all", $output);

Then I’m going to analyze output and decide to give it one more try, or throw an exception and quit my script.

Leave a Comment