Copyright (c) 2007 - 2008 by the dropr project https://www.dropr.org/
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of dropr nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
public function testPut() { $peer = dropr_Client_Peer_Abstract::getInstance('HttpUpload', 'http://localhost/droprserver/'); $dt = time(); $i = 0; // $m = $this->createMessage(1000); $m = "ich bin eine test message von " . date("H:m:i"); while ($i < 1) { $msg = $this->queue->createMessage($m, $peer); $msg->queue(); $i++; echo '.'; } $dt = time() - $dt; echo $dt . "\n"; echo "\n\n"; }
<?php require '../../client/classes/autoload.php'; $storage = dropr_Client_Storage_Abstract::factory('filesystem', '/home/soenke/droprclientqueue'); $queue = new dropr_Client($storage); $peer = dropr_Client_Peer_Abstract::getInstance('HttpUpload', 'http://soenkedroprserver/server/server.php'); $dt = time(); $i = 0; $m = json_encode(array("ich bin eine test message von " . date("H:i:s"), 'wurstarrayarray')); while ($i < 10000) { $msg = $queue->createMessage($m, $peer); $msg->queue(); $i++; echo '.'; } echo "\n";
pcntl_signal(SIGINT, 'handleKill'); /* * handle the alarm (wake-up from sleep) */ pcntl_signal(SIGALRM, 'handleAlarm'); while ($continue && $msgCount < $maxMessagesPerLife) { unset($queuedMessages, $peerMessages); 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);
public function getQueuedMessages($limit = null, &$peerKeyBlackList = null) { // expire blacklisted peers $now = time(); foreach ($peerKeyBlackList as $peerKey => $timeout) { if ($now > $timeout) { unset($peerKeyBlackList[$peerKey]); } } $spoolDir = $this->getSpoolPath(self::SPOOLDIR_TYPE_SPOOL) . DIRECTORY_SEPARATOR; $fNames = scandir($spoolDir); // unset the "." and the ".." unset($fNames[0]); unset($fNames[1]); $c = 1; $messages = array(); foreach ($fNames as $k => $fName) { if ($limit && $c > $limit) { break; } list($priority, $timeStamp, $encodedPeerKey, $encodedChannel) = explode('_', $fName, 4); $decodedPeerKey = $this->decodeFromFs($encodedPeerKey); $decodedChannel = $this->decodeFromFs($encodedChannel); $message = new dropr_Client_Message(NULL, new SplFileInfo($spoolDir . $fName), dropr_Client_Peer_Abstract::getInstance($decodedPeerKey), $decodedChannel, $priority); $message->restoreId($fName); if (!isset($peerKeyBlackList[$decodedPeerKey])) { $messages[$decodedPeerKey][] = $message; $c++; } } return $messages; }