/** * Some helper methods */ private function getTestUserClient($sessionId) { $config = Config::get('pushup')->server['default']; list($host, $port) = explode(':', array_shift($config['cluster'])); $tcpClient = new SC_TcpClient(); $tcpClient->setTimeout($config['connectTimeout'] * 50); $tcpClient->connect($host, $port); $tcpClient->write($sessionId); return $tcpClient; }
/** * Connect to pushup * * @throws SC_Pushup_Exception */ public function connect() { // check connection if (!$this->TcpClient->isOpen()) { $this->TcpClient->connect($this->host, $this->port); } // log in if ($this->loggedIn === false) { if ($this->backendPassword === null) { throw new SC_Pushup_Exception('no backend password set'); } // set logged in status and send password $this->loggedIn = true; $this->command(array($this->backendPassword)); } }
<?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"; }