Ejemplo n.º 1
0
 $pid = pcntl_fork();
 if ($pid == -1) {
     die("Could not fork!");
 } else {
     if ($pid) {
         // store the pid
         $fp = fopen(PIDFILE, "w+");
         fwrite($fp, $pid . "\n" . time());
         fclose($fp);
         while (file_exists(PIDFILE)) {
             usleep(50000);
         }
     } else {
         //$checker = new ProxyCheckerImpl();
         $checker = new ParanoidProxyCheckerImpl();
         $framework = new ProxyFramework("framework.db", $checker, 7200, 5400, 1, 30, 20, PIDFILE);
         $atom = new AtomintersoftModule();
         $samair = new SamairModule();
         $freechecker = new FreeCheckerModule();
         $nntime = new NNTimeModule();
         $framework->addModule($atom);
         // since samair.ru is down most of the time, perform this check before adding the samair module to PF
         print "Checking Samair\n";
         fw('samair.ru', 80, '-A');
         $test = shell_exec('curl -f samair.ru -m 20 --connect-timeout 20');
         //fw('samair.ru', 80, '-D');
         if (trim($test) != '' && strpos($test, "connect() timed out") === false) {
             $framework->addModule($samair);
         }
         $framework->addModule($freechecker);
         print "Checking NNTime\n";
 public static function handler($sig)
 {
     ProxyFramework::$instance->getLogger()->logEntry(LoggingImpl::LEVEL_DEBUG, "Handler called for PID " . posix_getpid() . "." . (ProxyFramework::$mainPid != null ? " Main PID is " . ProxyFramework::$mainPid . "." : ""));
     // the main process will call the shots
     $cond = posix_getpid() == ProxyFramework::$mainPid;
     if ($cond) {
         ProxyFramework::$instance->stop();
         ProxyFramework::$instance->getLogger()->logEntry(LoggingImpl::LEVEL_INFO, "Shutting down main process (" . ProxyFramework::$mainPid . ").");
         ProxyFramework::$mainPid = null;
     }
     // if shutdown trigger occurred out of lock block we can safely end the process here,
     // otherwise it should wait for the lock block to finish and end it there
     if (!$cond || !(ProxyFramework::$instance->getLockBlockState() & STATE_LOCKED)) {
         if ($cond) {
             ProxyFramework::$instance->getLogger()->logEntry(LoggingImpl::LEVEL_INFO, ProxyFramework::$instance->getLockBlockState() & STATE_LOCKED_CT ? "Shutdown occurred in checking thread lock block" : "Shutdown occurred out of lock block.");
         }
         die;
         // so that all threads exit
     }
 }