Beispiel #1
0
 public static function init()
 {
     self::$pid = \posix_getpid();
     self::$ppid = \posix_getppid();
     self::$child = array();
     self::$alias = array();
     self::$user_events = array();
     self::$shm_to_pid = array();
     // self::$shm_to_parent = -1;
     if (!self::$do_once) {
         // 初始化事件对象
         if (extension_loaded('libevent')) {
             self::$events = new Libevent();
         } else {
             self::$events = new Select();
         }
         self::$shm = new Shm(__FILE__, 'a');
         // 注册用户信号SIGUSR1处理函数
         self::onSysEvent(SIGUSR1, EventInterface::EV_SIGNAL, array("\\core\\proc\\Process", 'defaultSigusr1Cbk'));
         // 注册子进程退出处理函数
         self::onSysEvent(SIGCHLD, EventInterface::EV_SIGNAL, array("\\core\\proc\\Process", 'defaultSigchldCbk'));
         // 注册用户信号SIGUSR2处理函数
         self::onSysEvent(SIGUSR2, EventInterface::EV_SIGNAL, array("\\core\\proc\\Process", 'defaultSigusr2Cbk'));
         // 注册exit回调函数
         register_shutdown_function(function () {
             Process::closeShm();
         });
         self::$do_once = true;
     }
 }
Beispiel #2
0
<?php

require_once "vendor/autoload.php";
// use core\events\Libevent;
// use core\events\EventInterface;
// $event = new Libevent();
// $event->add(SIGUSR1, EventInterface::EV_SIGNAL, function ($fd, $event, $args = null){
//     print_r($fd);
//     echo "\n";
//     print_r($event);
//     echo "\n";
// });
// $event->add(SIGUSR2, EventInterface::EV_SIGNAL, function ($fd, $event, $args = null){
//     print_r($fd);
//     echo "\n";
//     print_r($event);
//     echo "\n";
// });
// $event->loop();
//
use core\proc\Process;
ini_set('memory_limit', '256M');
Process::init();
Process::fork('test1', function () {
    Process::loop();
});
// Process::sendMsg('test1', (array('msgtype' => 'command', 'msgname' => 'test', 'msgparam' => 'this is a test')));
Process::loop();