Пример #1
0
 /**
  * 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
 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']);
     $multi = new SC_Pushup_Multi();
     $multi->addInstance($pushup);
     return $multi;
 }