当前位置: 首页>>代码示例>>PHP>>正文


PHP TSocket::open方法代码示例

本文整理汇总了PHP中TSocket::open方法的典型用法代码示例。如果您正苦于以下问题:PHP TSocket::open方法的具体用法?PHP TSocket::open怎么用?PHP TSocket::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TSocket的用法示例。


在下文中一共展示了TSocket::open方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getAiravataClient

    public function getAiravataClient()
    {
        $transport = new TSocket($this->airavataServerHost, $this->airavataServerPort);
        $protocol = new TBinaryProtocol($transport);
	$transport->open();
        return new AiravataClient($protocol);
    }
开发者ID:sanyaade-iot,项目名称:airavata-php-gateway,代码行数:7,代码来源:AiravataClientFactory.php

示例2: __get

 public function __get($name)
 {
     if (isset($this->services[$name])) {
         if (is_string($this->services[$name])) {
             if (isset($this->service_config[$name])) {
                 $config = $this->service_config[$name];
                 if (empty($config['send_timeout'])) {
                     $config['send_timeout'] = $this->send_timeout;
                 }
                 if (empty($config['recv_timeout'])) {
                     $config['recv_timeout'] = $this->recv_timeout;
                 }
                 $transport = new TSocket($config['server_host'], $config['server_port']);
                 $transport->setSendTimeout($config['send_timeout'] * 1000);
                 $transport->setRecvTimeout($config['recv_timeout'] * 1000);
                 $transport->open();
                 $protocol = new TBinaryProtocol(new TBufferedTransport($transport));
                 $class = $this->services[$name];
                 $this->services[$name] = new $class($protocol);
             } else {
                 $transport = new TSocket($this->server_host, $this->server_port);
                 $transport->setSendTimeout($this->send_timeout * 1000);
                 $transport->setRecvTimeout($this->recv_timeout * 1000);
                 $transport->open();
                 $protocol = new TBinaryProtocol(new TBufferedTransport($transport));
                 $class = $this->services[$name];
                 $this->services[$name] = new $class($protocol);
             }
         }
         return $this->services[$name];
     } else {
         throw new Exception('Service Not Defined');
     }
 }
开发者ID:wheatma,项目名称:react_study,代码行数:34,代码来源:ThriftClient.php

示例3: hive_check

function hive_check($hive_host,$hive_port,$hive_send_timeout,$hive_recv_timeout) {
	$shell_ret=0;

	try{
		$transport = new TSocket($hive_host,$hive_port);
		$transport->setSendTimeout($hive_send_timeout);
		$transport->setRecvTimeout($hive_recv_timeout);
		$protocol = new TBinaryProtocol($transport);
		$client = new ThriftHiveClient($protocol);
		$transport->open();
		$client->execute('show databases');
		//var_dump($client->fetchAll());
	}catch(Exception $e){
		$shell_ret=1;
	}

	$transport->close();
	return $shell_ret;
}
开发者ID:recruitcojp,项目名称:WebHive,代码行数:19,代码来源:keepalive.php

示例4: while

 } else {
     $ip = $_GET['ip'];
     if ($handle = opendir('./hadoop')) {
         $i = 0;
         while (FALSE !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 $arr[$i] = $file;
                 $i++;
             }
         }
         closedir($handle);
     }
     $transport = new TSocket($ip, 30050);
     $protocol = new TBinaryProtocol($transport);
     #$client = new EasyHadoopClient($protocol);
     $transport->open();
     $install->MakeDir($protocol);
     foreach ($arr as $key => $value) {
         $filename = "/home/hadoop/" . $value;
         $fp = fopen("./hadoop/" . $value, "rb");
         while (!feof($fp)) {
             $content .= fread($fp, 1024);
         }
         fclose($fp);
         $str = $install->PushFile($filename, $content, $protocol);
         unset($content);
         sleep(1);
     }
     $transport->close();
     echo "<script>alert('" . $lang['pushComplete'] . "'); this.location='InstallManager.php?action=Install&ip=" . $ip . "';</script>";
 }
开发者ID:npk,项目名称:easyhadoop,代码行数:31,代码来源:InstallManager.php

示例5: open

 /**
  * Connects the socket by iterating through all the servers in the pool
  * and trying to find one that works.
  */
 public function open()
 {
     // Check if we want order randomization
     if ($this->randomize_) {
         shuffle($this->servers_);
     }
     // Count servers to identify the "last" one
     $numServers = count($this->servers_);
     for ($i = 0; $i < $numServers; ++$i) {
         // This extracts the $host and $port variables
         extract($this->servers_[$i]);
         // Check APC cache for a record of this server being down
         $failtimeKey = 'thrift_failtime:' . $host . ':' . $port . '~';
         // Cache miss? Assume it's OK
         $lastFailtime = apc_fetch($failtimeKey);
         if ($lastFailtime === FALSE) {
             $lastFailtime = 0;
         }
         $retryIntervalPassed = FALSE;
         // Cache hit...make sure enough the retry interval has elapsed
         if ($lastFailtime > 0) {
             $elapsed = time() - $lastFailtime;
             if ($elapsed > $this->retryInterval_) {
                 $retryIntervalPassed = TRUE;
                 if ($this->debug_) {
                     call_user_func($this->debugHandler_, 'TSocketPool: retryInterval ' . '(' . $this->retryInterval_ . ') ' . 'has passed for host ' . $host . ':' . $port);
                 }
             }
         }
         // Only connect if not in the middle of a fail interval, OR if this
         // is the LAST server we are trying, just hammer away on it
         $isLastServer = FALSE;
         if ($this->alwaysTryLast_) {
             $isLastServer = $i == $numServers - 1;
         }
         if ($lastFailtime === 0 || $isLastServer || $lastFailtime > 0 && $retryIntervalPassed) {
             // Set underlying TSocket params to this one
             $this->host_ = $host;
             $this->port_ = $port;
             // Try up to numRetries_ connections per server
             for ($attempt = 0; $attempt < $this->numRetries_; $attempt++) {
                 try {
                     // Use the underlying TSocket open function
                     parent::open();
                     // Only clear the failure counts if required to do so
                     if ($lastFailtime > 0) {
                         apc_store($failtimeKey, 0);
                     }
                     // Successful connection, return now
                     return;
                 } catch (TException $tx) {
                     // Connection failed
                 }
             }
             // Mark failure of this host in the cache
             $consecfailsKey = 'thrift_consecfails:' . $host . ':' . $port . '~';
             // Ignore cache misses
             $consecfails = apc_fetch($consecfailsKey);
             if ($consecfails === FALSE) {
                 $consecfails = 0;
             }
             // Increment by one
             $consecfails++;
             // Log and cache this failure
             if ($consecfails >= $this->maxConsecutiveFailures_) {
                 if ($this->debug_) {
                     call_user_func($this->debugHandler_, 'TSocketPool: marking ' . $host . ':' . $port . ' as down for ' . $this->retryInterval_ . ' secs ' . 'after ' . $consecfails . ' failed attempts.');
                 }
                 // Store the failure time
                 apc_store($failtimeKey, time());
                 // Clear the count of consecutive failures
                 apc_store($consecfailsKey, 0);
             } else {
                 apc_store($consecfailsKey, $consecfails);
             }
         }
     }
     // Holy shit we failed them all. The system is totally ill!
     $error = 'TSocketPool: All hosts in pool are down. ';
     $hosts = array();
     foreach ($this->servers_ as $server) {
         $hosts[] = $server['host'] . ':' . $server['port'];
     }
     $hostlist = implode(',', $hosts);
     $error .= '(' . $hostlist . ')';
     if ($this->debug_) {
         call_user_func($this->debugHandler_, $error);
     }
     throw new TException($error);
 }
开发者ID:euphoria,项目名称:thrift,代码行数:94,代码来源:TSocketPool.php

示例6: download


//.........这里部分代码省略.........
             }
             if ($link == null) {
                 $link = $links[0];
             }
         } else {
             $link = $links;
         }
     }
     if (strpos($link, "safeurl.")) {
         $newLocation = get_headers($link, 1);
         if (isset($newLocation["Location"])) {
             $link = $newLocation["Location"][0];
         } else {
             $contentWithLink = file_get_contents($link);
             preg_match_all("/(https:\\/\\/rapidshare[a-zA-Z0-9\\.\\-\\/_#+\\|!]*)/", $contentWithLink, $links);
             $links = array_unique($links[1]);
             $link = $links[0];
             $ex = explode("|", $link);
             $ex[0] = str_replace("/#!download", "/files/", $ex[0]);
             $link = $ex[0] . $ex[2] . "/" . $ex[3];
         }
     }
     if (strpos($link, "canhaz.")) {
         $newLocation = get_headers($link, 1);
         $link = $newLocation["Location"];
         $contentWithLink = file_get_contents($link);
         preg_match_all("/(http:\\/\\/rapidshare[a-zA-Z0-9\\.\\-\\/_#+]*)/", $contentWithLink, $links);
         $links = array_unique($links[1]);
         $link = $links[0];
     }
     $linkOld = $link;
     if ($this->A("JDLinkParser") != "") {
         $C = $this->A("JDLinkParser");
         $C = new $C();
         $link = $C->parse($link, $this->A("JDLinkParserUser"), $this->A("JDLinkParserPassword"));
     }
     if ($this->A("JDDLType") == "4") {
         if ($logFilename == "") {
             $info = get_headers($link, 1);
             if ($info !== false) {
                 preg_match("/filename=\"(.*)\"/ismU", $info["Content-Disposition"], $matches);
                 if (isset($matches[1])) {
                     $logFilename = $matches[1];
                 }
             }
         }
         if ($logFilename == "") {
             $logFilename = basename($link);
         }
         $DL = anyC::getFirst("Incoming", "IncomingUseForDownloads", "1");
         $size = $this->filesize($link);
         if ($size < 10 * 1024 * 1024) {
             throw new Exception("File size too small");
         }
         $id = $this->logDownload($logLink, $linkOld, $logFilename, $size, $Serie, true);
         file_put_contents($this->A("JDWgetFilesDir") . "/{$id}.temp", "-o wgetDL_" . str_pad($id, 5, "0", STR_PAD_LEFT) . ".log -O " . rtrim($DL->A("IncomingDir"), "/") . "/" . str_replace(" ", ".", basename($logFilename)) . "." . Util::ext($link) . " {$link}");
         rename($this->A("JDWgetFilesDir") . "/{$id}.temp", $this->A("JDWgetFilesDir") . "/{$id}.dl");
         chmod($this->A("JDWgetFilesDir") . "/{$id}.dl", 0666);
         return true;
     }
     if ($this->A("JDDLType") == "0") {
         Util::PostToHost($this->A("JDHost"), $this->A("JDPort"), "/link_adder.tmpl", "none", "do=Add&addlinks=" . urlencode($link), $this->A("JDUser"), $this->A("JDPassword"));
     }
     if ($this->A("JDDLType") == "1") {
         $xml = Util::PostToHost($this->A("JDHost"), $this->A("JDPort"), "/cgi-bin/Qdownload/DS_Login.cgi", "none", "user=" . $this->A("JDUser") . "&pwd=" . urlencode(base64_encode($this->A("JDPassword"))) . "&admin=1");
         $xml = new SimpleXMLElement(substr($xml, strpos($xml, "<?xml ")));
         $data = Util::PostToHost($this->A("JDHost"), $this->A("JDPort"), "/cgi-bin/Qdownload/DS_Task_Option.cgi", "none", "url=" . urlencode($link) . "&todo=add_rs&type=http_ftp&acc_id=1&user=&pwd=&sid=" . $xml->authSid . "&ver=2.0");
         $xml = new SimpleXMLElement(substr($data, strpos($data, "<?xml ")));
         if ($xml->Result . "" == "success") {
             $this->logDownload($logLink, $link, $logFilename, 0, $Serie);
         }
     }
     if ($this->A("JDDLType") == "2") {
         $content = file_get_contents("http://" . $this->A("JDHost") . ":" . $this->A("JDPort") . "/action/add/links/grabber0/start1/{$link}");
         if (strpos($content, "Link(s) added. (\"{$link}\"") !== false and $logLink != null) {
             $this->logDownload($logLink, $link, $logFilename, 0, $Serie);
         }
     }
     if ($this->A("JDDLType") == "3") {
         $GLOBALS['THRIFT_ROOT'] = Util::getRootPath() . "ubiquitous/Thrift";
         require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TTransport.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/packages/pyload/Pyload.php';
         require_once $GLOBALS['THRIFT_ROOT'] . '/packages/pyload/pyload_types.php';
         $transport = new TSocket($this->A("JDHost"), $this->A("JDPort") * 1);
         $transport->open();
         $protocol = new TBinaryProtocol($transport);
         $client = new PyloadClient($protocol);
         $client->login($this->A("JDUser"), $this->A("JDPassword"));
         #echo $client->getServerVersion();
         #echo "<br />";
         $client->addPackage("trinityDB", array($link), 1);
         #Print 'result = ' . $result;
         $transport->close();
     }
 }
开发者ID:nemiah,项目名称:trinityDB,代码行数:101,代码来源:JD.class.php

示例7: open

 /**
  * Connects the socket by iterating through all the servers in the pool
  * and trying to find one that:
  * 1. is not marked down after consecutive failures
  * 2. can really be connected to
  *
  * @return bool  false: any IP in the pool failed to connect before returning
  *               true: no failures
  */
 public function open()
 {
     // Check if we want order randomization
     if ($this->randomize_) {
         // warning: don't use shuffle here because it leads to uneven
         // load distribution
         $n = count($this->servers_);
         $s = $this->servers_;
         for ($i = 1; $i < $n; $i++) {
             $j = mt_rand(0, $i);
             $tmp = $s[$i];
             $s[$i] = $s[$j];
             $s[$j] = $tmp;
         }
         $this->servers_ = $s;
     }
     // Count servers to identify the "last" one
     $numServers = count($this->servers_);
     $has_conn_errors = false;
     $fail_reason = array();
     // reasons of conn failures
     for ($i = 0; $i < $numServers; ++$i) {
         // host port is stored as an array
         list($host, $port) = $this->servers_[$i];
         $failtimeKey = TSocketPool::getAPCFailtimeKey($host, $port);
         // Cache miss? Assume it's OK
         $lastFailtime = $this->apcFetch($failtimeKey);
         $this->apcLog("TSocketPool: host {$host}:{$port} last fail time: " . $lastFailtime);
         if ($lastFailtime === FALSE) {
             $lastFailtime = 0;
         }
         $retryIntervalPassed = FALSE;
         // Cache hit...make sure enough the retry interval has elapsed
         if ($lastFailtime > 0) {
             $elapsed = time() - $lastFailtime;
             if ($elapsed > $this->retryInterval_) {
                 $retryIntervalPassed = TRUE;
                 if ($this->debug_) {
                     call_user_func($this->debugHandler_, 'TSocketPool: retryInterval ' . '(' . $this->retryInterval_ . ') ' . 'has passed for host ' . $host . ':' . $port);
                 }
             }
         }
         // Only connect if not in the middle of a fail interval, OR if this
         // is the LAST server we are trying, just hammer away on it
         $isLastServer = FALSE;
         if ($this->alwaysTryLast_) {
             $isLastServer = $i == $numServers - 1;
         }
         if ($lastFailtime === 0 || $isLastServer || $lastFailtime > 0 && $retryIntervalPassed) {
             // Set underlying TSocket params to this one
             // fsockopen requires IPv6 addresses be bracet enclosed
             $this->host_ = $host;
             $this->port_ = $port;
             // Try up to numRetries_ connections per server
             for ($attempt = 0; $attempt < $this->numRetries_; $attempt++) {
                 try {
                     // Use the underlying TSocket open function
                     parent::open();
                     // Only clear the failure counts if required to do so
                     if ($lastFailtime > 0) {
                         $this->apcStore($failtimeKey, 0);
                     }
                     // Successful connection, return now
                     return !$has_conn_errors;
                 } catch (TException $tx) {
                     // Connection failed
                     // keep the reason for the last try
                     $errstr = $this->getErrStr();
                     $errno = $this->getErrNo();
                     if ($errstr !== null || $errno !== null) {
                         $fail_reason[$i] = '(' . $errstr . '[' . $errno . '])';
                     } else {
                         $fail_reason[$i] = '(?)';
                     }
                 }
             }
             // For transient errors (like Resource temporarily unavailable),
             // we might want not to cache the failure.
             if ($this->alwaysRetryForTransientFailure_ && $this->isTransientConnectFailure($this->getErrNo())) {
                 continue;
             }
             $has_conn_errors = $this->recordFailure($host, $port, $this->maxConsecutiveFailures_, $this->retryInterval_, $this->debug_ ? $this->debugHandler_ : null);
         } else {
             $fail_reason[$i] = '(cached-down)';
         }
     }
     // Holy shit we failed them all. The system is totally ill!
     $error = 'TSocketPool: All hosts in pool are down. ';
     $hosts = array();
     foreach ($this->servers_ as $i => $server) {
         // array(host, port) (reasons, if exist)
//.........这里部分代码省略.........
开发者ID:jamescarr,项目名称:fbthrift,代码行数:101,代码来源:TSocketPool.php

示例8: open

 public function open()
 {
     if (\hacklib_cast_as_boolean($this->randomize_)) {
         $n = count($this->servers_);
         $s = $this->servers_;
         for ($i = 1; $i < $n; $i++) {
             $j = mt_rand(0, $i);
             $tmp = $s[$i];
             $s[$i] = $s[$j];
             $s[$j] = $tmp;
         }
         $this->servers_ = $s;
     }
     $numServers = count($this->servers_);
     $has_conn_errors = false;
     $fail_reason = array();
     for ($i = 0; $i < $numServers; ++$i) {
         list($host, $port) = $this->servers_[$i];
         $failtimeKey = TSocketPool::getAPCFailtimeKey($host, $port);
         $lastFailtime = (int) $this->apcFetch($failtimeKey);
         $this->apcLog("TSocketPool: host {$host}:{$port} last fail time: " . $lastFailtime);
         $retryIntervalPassed = false;
         if ($lastFailtime > 0) {
             $elapsed = time() - $lastFailtime;
             if ($elapsed > $this->retryInterval_) {
                 $retryIntervalPassed = true;
                 if (\hacklib_cast_as_boolean($this->debug_) && $this->debugHandler_ !== null) {
                     $dh = $this->debugHandler_;
                     $dh('TSocketPool: retryInterval ' . '(' . $this->retryInterval_ . ') ' . 'has passed for host ' . $host . ':' . $port);
                 }
             }
         }
         $isLastServer = false;
         if (\hacklib_cast_as_boolean($this->alwaysTryLast_)) {
             $isLastServer = \hacklib_equals($i, $numServers - 1);
         }
         if ($lastFailtime === 0 || \hacklib_cast_as_boolean($isLastServer) || $lastFailtime > 0 && \hacklib_cast_as_boolean($retryIntervalPassed)) {
             $this->host_ = $host;
             $this->port_ = $port;
             for ($attempt = 0; $attempt < $this->numRetries_; $attempt++) {
                 try {
                     parent::open();
                     if ($lastFailtime > 0) {
                         $this->apcStore($failtimeKey, 0);
                     }
                     return;
                 } catch (TException $tx) {
                     $errstr = $this->getErrStr();
                     $errno = $this->getErrNo();
                     if ($errstr !== null || $errno !== null) {
                         $fail_reason[$i] = '(' . $errstr . '[' . $errno . '])';
                     } else {
                         $fail_reason[$i] = '(?)';
                     }
                 }
             }
             if (\hacklib_cast_as_boolean($this->alwaysRetryForTransientFailure_) && \hacklib_cast_as_boolean($this->isTransientConnectFailure($this->getErrNo()))) {
                 continue;
             }
             $dh = \hacklib_cast_as_boolean($this->debug_) ? $this->debugHandler_ : null;
             $has_conn_errors = $this->recordFailure($host, $port, $this->maxConsecutiveFailures_, $this->retryInterval_, $dh);
         } else {
             $fail_reason[$i] = '(cached-down)';
         }
     }
     $error = 'TSocketPool: All hosts in pool are down. ';
     $hosts = array();
     foreach ($this->servers_ as $i => $server) {
         list($host, $port) = $server;
         $h = $host . ':' . $port;
         if (\hacklib_cast_as_boolean(array_key_exists($i, $fail_reason))) {
             $h .= (string) $fail_reason[$i];
         }
         $hosts[] = $h;
     }
     $hostlist = implode(',', $hosts);
     $error .= '(' . $hostlist . ')';
     if (\hacklib_cast_as_boolean($this->debug_) && $this->debugHandler_ !== null) {
         $dh = $this->debugHandler_;
         $dh($error);
     }
     throw new TTransportException($error);
 }
开发者ID:davidnasar,项目名称:fbthrift,代码行数:83,代码来源:TSocketPool.php


注:本文中的TSocket::open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。