コード例 #1
0
ファイル: Helper.php プロジェクト: KWICKCommunity/Pushup
 /**
  * send data via pushup to notify a user in real time
  *
  * @param		int			$userid			id of user to send data to
  * @param		string		$function		function to call on client js
  * @param		array		$args			arguments for remotely called js function
  * @return		bool						success flag
  */
 public function send($userid, $function, $args = null)
 {
     $config = Config::get('pushup');
     // pushup active?
     if (!$config->enable) {
         return false;
     }
     // send message
     try {
         $config = $config->server['default'];
         // instantiate pushup instances
         $multi = new SC_Pushup_Multi();
         foreach ($config['cluster'] as $backend => $frontend) {
             list($host, $port) = explode(':', $backend);
             $tcpClient = new SC_TcpClient();
             $tcpClient->setTimeout($config['connectTimeout'] * 1000);
             $pushup = new SC_Pushup();
             $pushup->setTcpClient($tcpClient, $host, $port);
             $pushup->setBackendPassword($config['backendPass']);
             $multi->addInstance($pushup);
         }
         $multi->executeUser($userid, json_encode(array('func' => $function, 'args' => $args)));
         return true;
     } catch (SC_Pushup_Exception $e) {
     } catch (SC_TcpClient_Exception $e) {
     }
     return false;
 }
コード例 #2
0
ファイル: SingleTest.php プロジェクト: KWICKCommunity/Pushup
 protected function pushupGetInstance()
 {
     $config = Config::get('pushup')->server['default'];
     $host = array_keys($config['cluster']);
     list($host, $port) = explode(':', $host[0]);
     $tcpClient = new SC_TcpClient();
     $tcpClient->setTimeout($config['connectTimeout'] * 1000);
     $pushup = new SC_Pushup();
     $pushup->setTcpClient($tcpClient, $host, (int) $port);
     $pushup->setBackendPassword($config['backendPass']);
     return $pushup;
 }
コード例 #3
0
ファイル: test.php プロジェクト: KWICKCommunity/Pushup
<?php

set_include_path(dirname(dirname(__FILE__)) . '/php/lib');
require_once 'SC/TcpClient/Exception.php';
require_once 'SC/TcpClient.php';
require_once 'SC/Pushup/Exception.php';
require_once 'SC/Pushup/Interface.php';
require_once 'SC/Pushup.php';
try {
    // get tcp client
    $tcpClient = new SC_TcpClient('127.0.0.1', 6666);
    // set connect timeout
    $tcpClient->setTimeout(1 * 1000);
    // connect to server
    $tcpClient->connect();
    // set read timeout
    $tcpClient->setTimeout(1 * 1000);
    // get pushup
    $pushup = new SC_Pushup();
    // inject tcp client
    $pushup->setTcpClient($tcpClient);
    // set pushup backend password
    $pushup->setBackendPassword('secret');
    // execute javascript function "Test.alert" with argument "hallo" for the user with id 1
    $pushup->executeUser(1, json_encode(array('func' => 'PushupTest.alert', 'args' => 'Hello :-)')));
} catch (Exception $e) {
    echo get_class($e) . ' (' . $e->getMessage() . ")\n";
}
コード例 #4
0
ファイル: register.php プロジェクト: KWICKCommunity/Pushup
<?php

set_include_path(dirname(dirname(__FILE__)) . '/php/lib');
require_once 'SC/TcpClient/Exception.php';
require_once 'SC/TcpClient.php';
require_once 'SC/Pushup/Exception.php';
require_once 'SC/Pushup/Interface.php';
require_once 'SC/Pushup.php';
try {
    // get tcp client
    $tcpClient = new SC_TcpClient('127.0.0.1', 6666);
    // set connect timeout
    $tcpClient->setTimeout(1 * 1000);
    // connect to server
    $tcpClient->connect();
    // set read timeout
    $tcpClient->setTimeout(1 * 1000);
    // get pushup
    $pushup = new SC_Pushup();
    // inject tcp client
    $pushup->setTcpClient($tcpClient);
    // set pushup backend password
    $pushup->setBackendPassword('secret');
    // create a pushup entry for user 1 with session id "lociii"
    if ($pushup->createUser(1, 'lociii')) {
        echo 'success';
    }
} catch (Exception $e) {
    echo get_class($e) . ' (' . $e->getMessage() . ")\n";
}