public function __construct($keyspace, $server, $credentials, $framed_transport, $send_timeout, $recv_timeout) { $host = $server['host']; $port = $server['port']; $socket = new TSocket($host, $port); if ($send_timeout) { $socket->setSendTimeout($send_timeout); } if ($recv_timeout) { $socket->setRecvTimeout($recv_timeout); } if ($framed_transport) { $transport = new TFramedTransport($socket, true, true); } else { $transport = new TBufferedTransport($socket, 1024, 1024); } $client = new CassandraClient(new TBinaryProtocolAccelerated($transport)); $transport->open(); # TODO check API major version match $server_version = explode(".", $client->describe_version()); $server_version = $server_version[0]; if ($server_version < self::LOWEST_COMPATIBLE_VERSION) { $ver = self::LOWEST_COMPATIBLE_VERSION; throw new IncompatbleAPIException("The server's API version is too " . "low to be comptible with phpcassa (server: {$server_version}, " . "lowest compatible version: {$ver})"); } $client->set_keyspace($keyspace); if ($credentials) { $request = cassandra_AuthenticationRequest($credentials); $client->login($request); } $this->keyspace = $keyspace; $this->client = $client; $this->transport = $transport; }
public function __construct($keyspace, $server, $credentials = null, $framed_transport = True, $send_timeout = null, $recv_timeout = null) { $this->server = $server; $server = explode(':', $server); $host = $server[0]; if (count($server) == 2) { $port = (int) $server[1]; } else { $port = self::DEFAULT_PORT; } $socket = new \TSocket($host, $port); if ($send_timeout) { $socket->setSendTimeout($send_timeout); } if ($recv_timeout) { $socket->setRecvTimeout($recv_timeout); } if ($framed_transport) { $transport = new \TFramedTransport($socket, true, true); } else { $transport = new \TBufferedTransport($socket, 1024, 1024); } $this->client = new CassandraClient(new \TBinaryProtocolAccelerated($transport)); $transport->open(); $this->set_keyspace($keyspace); if ($credentials) { $request = new AuthenticationRequest(array("credentials" => $credentials)); $this->client->login($request); } $this->keyspace = $keyspace; $this->transport = $transport; $this->op_count = 0; }
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'); } }
public function __construct($keyspace, $server, $credentials, $framed_transport, $send_timeout, $recv_timeout) { $host = $server['host']; $port = $server['port']; $socket = new TSocket($host, $port); if ($send_timeout) { $socket->setSendTimeout($send_timeout); } if ($recv_timeout) { $socket->setRecvTimeout($recv_timeout); } if ($framed_transport) { $transport = new TFramedTransport($socket, true, true); } else { $transport = new TBufferedTransport($socket, 1024, 1024); } $client = new CassandraClient(new TBinaryProtocolAccelerated($transport)); $transport->open(); # TODO check API major version match $client->set_keyspace($keyspace); if ($credentials) { $request = cassandra_AuthenticationRequest($credentials); $client->login($request); } $this->keyspace = $keyspace; $this->client = $client; $this->transport = $transport; }
public function getAiravataClient() { $transport = new TSocket($this->airavataServerHost, $this->airavataServerPort); $protocol = new TBinaryProtocol($transport); $transport->open(); return new AiravataClient($protocol); }
public static function add_node($host, $port = self::DEFAULT_THRIFT_PORT, $framed_transport = false, $send_timeout = null, $recv_timeout = null, $persist = false) { try { // Create Thrift transport and binary protocol cassandra client $socket = new TSocket($host, $port, $persist); if ($send_timeout) { $socket->setSendTimeout($send_timeout); } if ($recv_timeout) { $socket->setRecvTimeout($recv_timeout); } if ($framed_transport) { $transport = new TFramedTransport($socket, true, true); } else { $transport = new TBufferedTransport($socket, 1024, 1024); } $client = new CassandraClient(new TBinaryProtocolAccelerated($transport)); // Store it in the connections self::$connections[] = array('transport' => $transport, 'client' => $client); // Done return TRUE; } catch (TException $tx) { self::$last_error = 'TException: ' . $tx->getMessage() . "\n"; } return FALSE; }
/** * Create connector object * @param array $config * @return TTransport */ private static function getConnector($config) { $class = isset($config['class']) ? $config['class'] : ''; $param = isset($config['param']) ? $config['param'] : array(); switch ($class) { case 'THttpClient': if (!isset($param['host'])) { throw new Exception('Bad Thrift transport config'); } $host = $param['host']; $port = isset($param['port']) ? $param['port'] : 80; $uri = isset($param['uri']) ? $param['uri'] : ''; $scheme = isset($param['scheme']) ? $param['scheme'] : 'http'; $timeout = isset($param['timeout']) ? $param['timeout'] : null; $connector = new THttpClient($url, $port, $uri, $scheme); $connector->setTimeoutSecs($timeout); $parameters = sprintf('host = "%s", port = %d, uri = "%s", scheme = "%s", timeout = %d', $host, $port, $uri, $scheme, $timeout); break; case 'TMemoryBuffer': $buf = isset($param['buf']) ? $param['buf'] : ''; $connector = new TMemoryBuffer($buf); $parameters = sprintf('buf = "%s"', $buf); break; case 'TPhpStream': if (!isset($param['mode'])) { throw new Exception('Bad Thrift transport config'); } $mode = $param['mode']; $connector = new TPhpStream($mode); $parameters = sprintf('mode = %d', $mode); break; case 'TSocket': $host = isset($param['host']) ? $param['host'] : 'localhost'; $port = isset($param['port']) ? $param['port'] : 9090; $persist = isset($param['persist']) ? $param['persist'] : false; $send_timeout = isset($param['send_timeout']) ? $param['send_timeout'] : 100; $recv_timeout = isset($param['recv_timeout']) ? $param['recv_timeout'] : 750; $connector = new TSocket($host, $port, $persist); $connector->setSendTimeout($send_timeout); $connector->setRecvTimeout($recv_timeout); $parameters = sprintf('host = "%s", port = %d, persist = %s, send_timeout = %d, recv_timeout = %d', $host, $port, $persist ? 'true' : 'false', $send_timeout, $recv_timeout); break; case 'TSocketPool': $hosts = isset($param['hosts']) ? $param['hosts'] : array('localhost'); $ports = isset($param['ports']) ? $param['ports'] : array(9090); $persist = isset($param['persist']) ? $param['persist'] : false; $send_timeout = isset($param['send_timeout']) ? $param['send_timeout'] : 100; $recv_timeout = isset($param['recv_timeout']) ? $param['recv_timeout'] : 750; $connector = new TSocketPool($hosts, $ports, $persist); $connector->setSendTimeout($send_timeout); $connector->setRecvTimeout($recv_timeout); $parameters = sprintf('hosts = ("%s"), ports = (%d), persist = %s, send_timeout = %d, recv_timeout = %d', implode('","', $hosts), implode('","', $ports), $persist ? 'true' : 'false', $send_timeout, $recv_timeout); break; default: throw new Exception('Unknown connector: ' . $class); } sfContext::getInstance()->getLogger()->info(sprintf('{sfThriftPlugin}Create %s connector with parameters: %s', $class, $parameters)); return $connector; }
public function initialize($param) { $this->host = $param['host']; $this->port = $param['port']; $socket = new \TSocket($this->host, $this->port); $socket->setSendTimeout(2000); $socket->setRecvTimeout(5000); $transport = new \TBufferedTransport($socket, 512, 512); $protocol = new \TBinaryProtocol($transport); $this->hbaseThriftClient = new \THBaseServiceClient($protocol); $transport->open(); }
function __construct($host, $port, $timeout_ms = 300000, $do_open = true) { $socket = new TSocket($host, $port); $socket->setSendTimeout($timeout_ms); $socket->setRecvTimeout($timeout_ms); $this->transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($this->transport); parent::__construct($protocol); if ($do_open) { $this->open(); } }
function __construct($options) { $config = Zend_Registry::get('configuration'); $this->socket = new TSocket($config->stdprofile->host, $config->stdprofile->port); $this->socket->setSendTimeout($this->sendTimeout); $this->socket->setRecvTimeout($this->recvTimeout); $this->transport = new TFramedTransport($this->socket); $this->protocol = new TBinaryProtocolAccelerated($this->transport); $this->client = new StdProfile2Service_RdClient($this->protocol); $this->_handle = new zcommon_OpHandle(); $this->_handle->source = $config->stdprofile->source; $this->_handle->auth = $config->stdprofile->auth; }
public static function connect($params = array()) { self::$config = $params; // Initialize Thrift connection $socket = new \TSocket($params["server"], 9090); $socket->setSendTimeout(3000); $socket->setRecvTimeout(10000); $transport = new \TBufferedTransport($socket); $protocol = new \TBinaryProtocol($transport); $client = new \HbaseClient($protocol); $transport->open(); self::$hbase = new ThriftHBaseClientWrapper($client); }
private function __construct() { try { $socket = new TSocket('localhost', '9030'); $socket->setRecvTimeout(50000); $this->transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new TedServiceClient($protocol); $this->transport->open(); } catch (TException $tx) { // a general thrift exception, like no such server echo "ThriftException: " . $tx->getMessage() . "\r\n"; } }
private function connect() { try { $options = array('host' => '10.30.22.135', 'port' => 7114); $socket = new TSocket($options['host'], $options['port']); $socket->setSendTimeout(10000); $socket->setRecvTimeout(10000); $this->transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new TTokenClient($protocol); } catch (Exception $e) { throw $e; } }
/** * Constructor. Initialize the model object * * @param array $conf The global config information */ function __construct($conf) { $this->sql_database = null; $this->hive_database = null; if ($conf['database_type'] == 'mysql') { $this->sql_database = new medoo(array('database_type' => 'mysql', 'database_name' => $conf['default_schema'], 'server' => $conf['host'], 'port' => $conf['port'], 'username' => $conf['user'], 'password' => $conf['password'])); } if ($conf['database_type'] == 'hive') { $transport = new TSocket($conf['host'], $conf['port']); $transport->setSendTimeout(600 * 1000); $transport->setRecvTimeout(600 * 1000); $this->hive_database = new ThriftHiveClientEx(new TBinaryProtocol($transport)); } }
private function connect() { try { $config = $this->getConfig(); $options = array('host' => $config->thrift->host, 'port' => $config->thrift->port); $socket = new TSocket($options['host'], $options['port']); $socket->setSendTimeout($config->thrift->timeout->send); $socket->setRecvTimeout($config->thrift->timeout->recv); $this->transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new T_PaymentBOClient($protocol); } catch (Exception $e) { throw $e; } }
public function accept($timeout = -1) { if ($timeout !== 0) { $client = stream_socket_accept($this->handle, $timeout); } else { $client = stream_socket_accept($this->handle, $timeout); } if (!\hacklib_cast_as_boolean($client)) { return null; } $socket = new TSocket(); $socket->setHandle($client); $transport = new TBufferedTransport($socket, $this->send_buffer_size, $this->recv_buffer_size); return $transport; }
private function connect() { try { $config = Zend_Registry::get('appconf'); $options = array('host' => $config->billing->host, 'port' => $config->billing->port); $socket = new TSocket($options['host'], $options['port']); $socket->setSendTimeout($config->billing->connection->sendtimeout); $socket->setRecvTimeout($config->billing->connection->recvtimeout); $this->transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new TPaymentClient($protocol); } catch (Exception $e) { throw $e; } }
private function connect() { try { $config = Zend_Registry::get('appconf'); $options = array('host' => $config->token->host, 'port' => $config->token->port); /* $options = array('host'=>'10.199.18.36', 'port'=>7114);*/ $socket = new TSocket($options['host'], $options['port']); $socket->setSendTimeout($config->token->connection->sendtimeout); $socket->setRecvTimeout($config->token->connection->sendtimeout); $this->transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new TTokenClient($protocol); } catch (Exception $e) { throw $e; } }
private function connect() { try { // $config = $this->getConfig(); // $options = array('host'=>$config->thrift->host, // 'port'=>$config->thrift->port); $options = array('host' => '10.30.22.135', 'port' => 6161); $socket = new TSocket($options['host'], $options['port']); $socket->setSendTimeout(1000); $socket->setRecvTimeout(1000); $this->transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($this->transport); $this->client = new TPaymentClient($protocol); } catch (Exception $e) { throw $e; } }
public function accept($timeout = -1) { if ($timeout !== 0) { $client = stream_socket_accept($this->handle, $timeout); } else { $client = @stream_socket_accept($this->handle, $timeout); } if (!$client) { return false; } $socket = new TSocket(); $socket->setHandle($client); // We need to create a buffered transport because TSocket's isReadable // is not reliable in PHP (hphp is fine) and buffered transport is more // efficient (60% faster in my tests) $transport = new TBufferedTransport($socket, $this->send_buffer_size, $this->recv_buffer_size); return $transport; }
public static function add_node($host, $port = self::DEFAULT_THRIFT_PORT, $perist = true, $read_timeoutms = 300) { try { // Create Thrift transport and binary protocol cassandra client $sock = new TSocket($host, $port, $perist); $sock->setRecvTimeout(10000); $sock->setDebug('error_log'); $transport = new TBufferedTransport($sock, 10240, 10240); $client = new CassandraClient(new TBinaryProtocolAccelerated($transport)); // Store it in the connections self::$connections[] = array('transport' => $transport, 'client' => $client); // Done return TRUE; } catch (TException $tx) { self::$last_error = 'TException: ' . $tx->getMessage() . "\n"; } return FALSE; }
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; }
/** * Implementation of accept. If not client is accepted in the given time * * @return TSocket */ protected function acceptImpl() { $handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0); if (!$handle) { return null; } $socket = new TSocket(); $socket->setHandle($handle); return $socket; }
public function __construct($keyspace, $server, $credentials = null, $framed_transport = True, $send_timeout = null, $recv_timeout = null) { $this->server = $server; $server = explode(':', $server); $host = $server[0]; if (count($server) == 2) { $port = (int) $server[1]; } else { $port = self::DEFAULT_PORT; } $socket = new TSocket($host, $port); if ($send_timeout) { $socket->setSendTimeout($send_timeout); } if ($recv_timeout) { $socket->setRecvTimeout($recv_timeout); } if ($framed_transport) { $transport = new TFramedTransport($socket, true, true); } else { $transport = new TBufferedTransport($socket, 1024, 1024); } $client = new CassandraClient(new TBinaryProtocolAccelerated($transport)); $transport->open(); $server_version = explode(".", $client->describe_version()); $server_version = $server_version[0]; if ($server_version < self::LOWEST_COMPATIBLE_VERSION) { $ver = self::LOWEST_COMPATIBLE_VERSION; throw new IncompatibleAPIException("The server's API version is too " . "low to be comptible with phpcassa (server: {$server_version}, " . "lowest compatible version: {$ver})"); } $client->set_keyspace($keyspace); if ($credentials) { $request = new cassandra_AuthenticationRequest(array("credentials" => $credentials)); $client->login($request); } $this->keyspace = $keyspace; $this->client = $client; $this->transport = $transport; $this->op_count = 0; }
$t_start = microtime(true); $got = fwrite($this->handle_, $buf); $write_time = microtime(true) - $t_start; if ($got === 0 || !\hacklib_cast_as_boolean(is_int($got))) { $read_err_detail = sprintf('%d bytes from %s:%d to localhost:%d. Spent %2.2f ms.', $buflen, $this->host_, $this->port_, $this->lport_, $write_time * 1000); $md = stream_get_meta_data($this->handle_); if (\hacklib_cast_as_boolean($md[\hacklib_id('timed_out')])) { throw new TTransportException('TSocket: timeout while writing ' . $read_err_detail, TTransportException::TIMED_OUT); } else { $md_str = str_replace("\n", " ", print_r($md, true)); throw new TTransportException('TSocket: could not write ' . $read_err_detail, TTransportException::COULD_NOT_WRITE); } } $buf = substr($buf, $got); } $this->writeAttemptStart_ = null; } public function flush() { $ret = fflush($this->handle_); if ($ret === false) { throw new TTransportException('TSocket: could not flush ' . $this->host_ . ':' . $this->port_); } } public static function hacklib_initialize_statics() { self::hacklib_initialize_statics_InstrumentedTTransportTrait(); } } TSocket::hacklib_initialize_statics();
echo '</tbody> </table>'; echo '</div>'; } 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); }
define('CODE_BASE2', '/server/www/code_base'); $GLOBALS['THRIFT_ROOT'] = !isset($GLOBALS['THRIFT_ROOT']) ? CODE_BASE2 . '/third_part/thrift-0.5.0' : $GLOBALS['THRIFT_ROOT']; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/packages/scribe/scribe.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/THttpClient.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php'; //生成的文件 require_once dirname(__FILE__) . '/Hive.php'; //数据库文件 include_once '../DB/MyDB.class.php'; ERROR_REPORTING(E_ALL); INI_SET('DISPLAY_ERRORS', 'ON'); $socket = new TSocket('hive.corp.xx.com', 13080); $socket->setDebug(TRUE); // 设置接收超时(毫秒) $socket->setSendTimeout(10000); $socket->setRecvTimeout(30 * 60 * 1000); //接受时间设置为30分钟 //$transport = new TBufferedTransport($socket, 1024, 1024); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $client = new HiveClient($protocol); try { $transport->open(); } catch (TException $tx) { echo $tx->getMessage(); exit; }
<?php include_once 'config.inc.php'; if (!$_GET['database']) { $file = "js/hiveudfs.txt"; $array = file($file); } else { if (!$_GET['table']) { $file = "js/hiveudfs.txt"; $array = file($file); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('use ' . $_GET['database']); $sql = "desc " . $_GET['table']; $client->execute($sql); $array_desc_table = $client->fetchAll(); $i = 0; while ('' != @$array_desc_table[$i]) { $array_desc = explode(' ', $array_desc_table[$i]); $array_desc_desc[$i] = $array_desc[0]; $i++; } $array_table = array($_GET['table']); $file = "js/hiveudfs.txt"; $array = file($file); $array = array_merge($array, $array_desc_desc); $array = array_merge($array, $array_table); }
/** * 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); }
public function download($link, $logLink = null, $logFilename = "", Serie $Serie = null) { if (strpos($link, "linksafe.")) { $newLocation = get_headers($link, 1); $links = $newLocation["Location"]; $link = null; if (is_array($links)) { foreach ($links as $k => $l) { if (stripos($l, "https") === 0) { $link = $links[$k]; } } 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="******"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(); } }