SommaireTelecharger la documentationChapitre suivantChapitre precedent  

  .: News :.: Edito :.: Scripts :.: Forum :.: Erreurs :.: Jobs :. 
 
Sommaire

Contrôle des processus

Exemple de contrôle de processus
pcntl_fork
pcntl_signal
pcntl_waitpid
pcntl_wexitstatus
pcntl_wifexited
pcntl_wifsignaled
pcntl_wifstopped
pcntl_wstopsig
pcntl_wtermsig

6.79.1 Exemple de contrôle de processus

Cet exemple effectue un fork du processus démon grâce à un gestionnaire de signaux.

Process Control Example

<?php
  $pid 
pcntl_fork();
  if (
$pid == -1) {
     die(
"could not fork"); 
  } else if (
$pid) {
     exit(); 
// we are the parent
  
} else {
     
// we are the child
  
}
// detatch from the controlling terminal
  
if (!posix_setsid()) {
    die(
"could not detach from terminal");
  }
// setup signal handlers
  
pcntl_signal(SIGTERM"sig_handler");
  
pcntl_signal(SIGHUP"sig_handler");
// loop forever performing tasks
  
while(1) {
    
// do something interesting here
}
function 
sig_handler($signo) {
     switch(
$signo) {
         case 
SIGTERM:
             
// handle shutdown tasks
             
exit;
             break;
         case 
SIGHUP:
             
// handle restart tasks
             
break;
         default:
             
// handle all other signals
     
}
}
?<

Chapitre précédentChapitre suivantAccueil nexen.net