private function init($socket) { $transport = new TFramedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $this->client = new \ipqueryClient($protocol); $transport->open(); }
/** * Open the connection * * @return static * * @throws ConnectionException */ public function connect() { if ($this->_client === null) { $remainingAttempts = (int) $this->_config()->getItem('connect_attempts', 1); while ($remainingAttempts > 0) { $remainingAttempts--; $exception = null; try { if (empty($this->_availableHosts)) { $this->_availableHosts = ValueAs::arr($this->_config()->getItem('hosts', 'localhost')); $this->_availableHostCount = count($this->_availableHosts); if ($this->_availableHostCount < 1) { throw new ConnectionException('Could not find any configured hosts'); } } shuffle($this->_availableHosts); $host = reset($this->_availableHosts); $this->_socket = new DalSocket($host, (int) $this->_config()->getItem('port', 9160), ValueAs::bool($this->_config()->getItem('persist', false))); $this->_socket->setConnectTimeout((int) $this->_config()->getItem('connect_timeout', 1000)); $this->_socket->setRecvTimeout((int) $this->_config()->getItem('receive_timeout', 1000)); $this->_socket->setSendTimeout((int) $this->_config()->getItem('send_timeout', 1000)); $this->_transport = new TFramedTransport($this->_socket); $this->_protocol = new TBinaryProtocolAccelerated($this->_transport); $this->_client = new CassandraClient($this->_protocol); $this->_transport->open(); $this->_connected = true; $this->_clearStmtCache(); $username = $this->_config()->getItem('username'); // @codeCoverageIgnoreStart if ($username) { $this->_client->login(new AuthenticationRequest(['credentials' => ['username' => $username, 'password' => $this->_config()->getItem('password', '')]])); } //@codeCoverageIgnoreEnd $this->_switchDatabase(null, !$this->_socket->isPersistent()); } catch (TException $e) { $exception = $e; } catch (CqlException $e) { $exception = $e; } if ($exception) { $this->_removeCurrentHost(); $this->disconnect(); if ($remainingAttempts < 1) { if (!$exception instanceof CqlException) { $exception = CqlException::from($exception); } throw new ConnectionException('Failed to connect: ' . $exception->getMessage(), $exception->getCode(), $exception->getPrevious()); } } else { break; } } } return $this; }
public function __construct($host, $port) { try { $socket = new TSocket($host, $port); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $transport->open(); $this->_searchService = new ThriftSearchServiceClient($protocol); } catch (TException $tx) { throw FirteXException($tx->getMessage()); } }
private function _send($mobiles, $message) { try { $socket = new TSocketPool($this->config['msg_server_host'], $this->config['msg_server_port']); $transport = new TFramedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $transport->open(); $client = new \mobilemsg\service\MsgOper_ServiceClient($protocol); $identity = new \mobilemsg\service\Identity(array('version' => $GLOBALS['mobilemsg_CONSTANTS']['version'], 'appId' => $this->config['app_id'], 'appKey' => $this->config['app_key'])); $sent_control = new \mobilemsg\service\SentControl(); $type = 0; $downMsg = new \mobilemsg\service\DownMsg(); $downMsg->mobiles = $mobiles; $downMsg->smsContent = $this->alert->build_msg($message); $downMsg->muid = $mobiles[0] . '_' . time(); $msg = array(0 => $downMsg); $ret = $client->send($identity, $type, $msg, $sent_control); $this->log("task worker {$this->worker_id} send msg result" . var_export($ret, 1)); //业务代码end $transport->close(); } catch (TException $tx) { $this->log("task worker {$this->worker_id} thrift Exception " . var_export($tx, 1)); } }
} $result = array('code' => 0, 'data' => array()); /* //ip白名单判断 if( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; if( !check_ip($white_ip_array, $_SERVER['REMOTE_ADDR']) ){ $result['code'] = -1; //ip不再白名单内 echo json_encode($result); exit; } */ try { $socket = new TSocketPool(array('115.238.170.51', '121.9.221.159', '113.106.100.79'), 30303); $transport = new TFramedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $transport->open(); //业务代码begin //注册验证码接口 define('APPID', 77); define('APPKEY', 'stats20151007'); //邀请短信接口 //define('APPID', 44); //define('APPKEY', 'secretInvite'); //define('APPID', 2); //define('APPKEY', 'test'); $client = new \mobilemsg\service\MsgOper_ServiceClient($protocol); $identity = new \mobilemsg\service\Identity(array('version' => $GLOBALS['mobilemsg_CONSTANTS']['version'], 'appId' => APPID, 'appKey' => APPKEY)); $sent_control = new \mobilemsg\service\SentControl(); $type = 0; $downMsg = new \mobilemsg\service\DownMsg(); $downMsg->mobiles = array('18588746832');
use Thrift\Transport\TSocket; use Thrift\Transport\TFramedTransport; use Thrift\Exception\TException; use scribe\thrift\scribeClient; use scribe\thrift\LogEntry; use scribe\thrift\ResultCode; try { $sock = new TSocket('localhost', 1463); $trans = new TFramedTransport($sock); $prot = new TBinaryProtocol($trans); // Create the client print "creating scribe client\n"; $scribe_client = new scribeClient($prot); // Open the transport (we rely on PHP to close it at script termination) print "opening transport\n"; $trans->open(); $entry = new LogEntry(); $entry->category = "PHP"; $entry->message = "Hello to Scribe from PHP!"; $messages[] = $entry; for ($x = 0; $x <= 0; $x++) { $result = $scribe_client->Log($messages); if ($result != ResultCode::OK) { print "Warning: Log returned {$result} \n"; } } $time_end = microtime(true); $time = $time_end - $time_start; echo "DONE after {$time} seconds\n"; } catch (Exception $x) { print "Unable to create global scribe client, received exception: {$x} \n";