Exemple #1
0
 public static function fork($target)
 {
     if (!is_callable($target) && !$target instanceof Runnable) {
         throw new ConsoleException("Must be callable or Runnable.");
     }
     $pid = pcntl_fork();
     if (0 === $pid) {
         try {
             if ($target instanceof Runnable) {
                 $result = $target->run();
             } else {
                 $result = call_user_func($target);
             }
         } catch (\Exception $ex) {
             throw new ConsoleException($ex->getMessage(), $ex);
         }
         App::end($result);
     }
     if (0 > $pid) {
         throw new ConsoleException("Process start failure.");
     }
     $process = new Process($pid);
     return $process;
 }
Exemple #2
0
 private function initialize()
 {
     if (!function_exists("pcntl_signal_dispatch")) {
         declare (ticks=10);
     }
     $this->registeSignalHandler(function ($signal) {
         switch ($signal) {
             case SIGTERM:
             case SIGHUP:
             case SIGQUIT:
                 $this->onStop();
                 App::end();
                 break;
             default:
                 return false;
         }
         return true;
     });
     if (function_exists("gc_enable")) {
         gc_enable();
     }
 }