- constants - logging - autoloading
Author: Soenke Ruempler (soenke@ruempler.eu)
Example #1
0
 public function __construct(dropr_Client_Storage_Abstract $storage)
 {
     $ipcPath = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'droprIpc' . DIRECTORY_SEPARATOR;
     $channelName = $ipcPath . hash('sha1', realpath($storage->getDsn()));
     $this->storage = $storage;
     if (!is_dir($ipcPath)) {
         mkdir($ipcPath, 0777, true);
     }
     if (!is_file($channelName)) {
         if (!posix_mknod($channelName, 0666)) {
             throw new Exception("could not mknod {$channelName}!");
         }
     }
     dropr::log("doing ftok({$channelName})", LOG_DEBUG);
     $this->ipcChannel = msg_get_queue(ftok($channelName, '*'));
 }
Example #2
0
 /**
  * Get the Logger instance
  * 
  * @return dropr_Log
  */
 public static function getLogger()
 {
     if (!self::$logger) {
         // get the default error_log logger
         self::$logger = new dropr_Log_Errorlog();
     }
     return self::$logger;
 }
Example #3
0
    if ($queuedMessages = $storage->getQueuedMessages($maxMessagesPerSend, $peerKeyBlackList)) {
        dropr::log("got " . count($queuedMessages, COUNT_RECURSIVE) . " messages from the storage", LOG_DEBUG);
        foreach ($queuedMessages as $peerKey => $peerMessages) {
            /*
             * count the messages regardless they can be sent or not
             */
            $msgCount += count($peerMessages, COUNT_RECURSIVE);
            try {
                $peer = dropr_Client_Peer_Abstract::getInstance($peerKey);
                dropr::log("trying to send messages to peer `" . $peer->getUrl() . "' via method `" . $peer->getTransportMethod() . "'", LOG_DEBUG);
                $result = $peer->send($peerMessages, $storage);
                $storage->checkSentMessages($peerMessages, $result);
                dropr::log("successfully sent messages to the peer!", LOG_DEBUG);
            } catch (Exception $e) {
                $peerKeyBlackList[$peerKey] = time() + $peerTimeout;
                dropr::log("could not sent messages to peer {$peer->getUrl()}- message was: {$e->getMessage()}  - blacklisting the peer for {$peerTimeout} seconds!");
            }
        }
    } else {
        dropr::log("nothing to do. going to sleep.", LOG_DEBUG);
        pcntl_alarm($sleepTimeout);
        @msg_receive($ipcChannel, 1, $msgType, 512, $msg, true, 0, $msgError);
        dropr::log("woke up from sleep - checking for messages ...", LOG_DEBUG);
        pcntl_alarm(0);
    }
}
if ($continue) {
    dropr::log("Restarting after sending {$maxMessagesPerLife} messages into the world.", LOG_INFO);
} else {
    dropr::log("Cleaning up and terminating on request. Goodbye.", LOG_INFO);
}