2010-06-08 7 views

Répondre

1

Vous pouvez vérifier l'extension ncurse. Non documenté mais ncurses_getch devrait être ce que vous cherchez. Ctrl + C envoie SIGINT qui, par défaut, termine immédiatement une application ou un script.

1

Si vous créez une capture pour cela, vous pouvez faire en sorte que votre script se termine plus proprement.

<?php 
declare(ticks = 1); 

pcntl_signal(SIGTERM, "sig_handle"); 
pcntl_signal(SIGINT, "sig_handle"); 
$TERMINATE = false; 

function sig_handle($signal) 
{ 
    switch($signal) 
    { 
     case SIGTERM: 
      print "Got SIGTERM\n"; 
      $TERMINATE = true; 
     break; 
     case SIGKILL: 
      print "Got SIGKILL\n"; 
      $TERMINATE = true; 
     break; 
     case SIGINT: 
      print "User pressed Ctrl+C - Got SIGINT\n"; 
      $TERMINATE = true; 
     break; 
    } 
} 


while(true) 
{ 
    // Do everything and anything - though infinite loops, not the best idea. 
    if($TERMINATE) 
    { 
      // Perform all cleaning functions. 
      // Then break the loop 
      break 2; 
    } 
} 

// Just because Ctl+C was passed it only broke the loop, you can add other hooks into your program to help capture this break and more quickly terminate your script. 
?> 
+0

Pendant que cette solution fonctionne, pcntl_signal() ne fonctionne que sur les systèmes non-Windows. http://www.php.net/manual/en/pcntl.installation.php – BOMEz

Questions connexes