Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/10/2010, 17:46
Avatar de dreamconception
dreamconception
 
Fecha de Ingreso: octubre-2010
Ubicación: Mexico-Dinamarca
Mensajes: 22
Antigüedad: 13 años, 7 meses
Puntos: 2
Respuesta: Arrancar proceso en linux usando PHP

Ver http://www.php.net/manual/en/function.exec.php

El commentario;
Cita:
[NOTE BY danbrown AT php DOT net: The following is a Linux script that the contributor of this note suggests be placed in a file named 'pstools.inc.php' to execute a process, check if a process exists, and kill a process by ID. Inspired by the Windows version at http://php.net/exec#59428 ]

Código PHP:
Ver original
  1. <?php
  2.   function PsExecute($command, $timeout = 60, $sleep = 2) {
  3.         // First, execute the process, get the process ID
  4.  
  5.         $pid = PsExec($command);
  6.  
  7.         if( $pid === false )
  8.             return false;
  9.  
  10.         $cur = 0;
  11.         // Second, loop for $timeout seconds checking if process is running
  12.         while( $cur < $timeout ) {
  13.             sleep($sleep);
  14.             $cur += $sleep;
  15.             // If process is no longer running, return true;
  16.  
  17.            echo "\n ---- $cur ------ \n";
  18.  
  19.             if( !PsExists($pid) )
  20.                 return true; // Process must have exited, success!
  21.         }
  22.  
  23.         // If process is still running after timeout, kill the process and return false
  24.         PsKill($pid);
  25.         return false;
  26.     }
  27.  
  28.     function PsExec($commandJob) {
  29.  
  30.         $command = $commandJob.' > /dev/null 2>&1 & echo $!';
  31.         exec($command ,$op);
  32.         $pid = (int)$op[0];
  33.  
  34.         if($pid!="") return $pid;
  35.  
  36.         return false;
  37.     }
  38.  
  39.     function PsExists($pid) {
  40.  
  41.         exec("ps ax | grep $pid 2>&1", $output);
  42.  
  43.         while( list(,$row) = each($output) ) {
  44.  
  45.                 $row_array = explode(" ", $row);
  46.                 $check_pid = $row_array[0];
  47.  
  48.                 if($pid == $check_pid) {
  49.                         return true;
  50.                 }
  51.  
  52.         }
  53.  
  54.         return false;
  55.     }
  56.  
  57.     function PsKill($pid) {
  58.         exec("kill -9 $pid", $output);
  59.     }
  60. ?>
Utilizes un timeout, y kill la ejecucion cuando el tiempo de espera se ha alcanzado.

Es eso lo que tu necesites?