/** * Destroys the environment after each test method is run * * @return void * @access public */ public function endTest() { $this->mongodb = new MongodbSource($this->_config); $this->mongodb->connect(); $this->dropData(); unset($this->mongodb); }
/** * Opens the memcache based session storage handler * * @access protected */ protected function _open() { $this->_conn = new Memcache(); if ($this->_conn->connect('localhost', 11211) !== true) { // fallback to the default PHP session storage mechanism session_module_name($this->_orig_module_name); return $this->start(); } return true; }
/** * Constructor * * @param string $host the memcached server host * @param int $port the memcached server port * @param int $timeout the default timeout * * @return void */ function __construct($host = 'localhost', $port = 11211, $timeout = 3600) { $this->_host = $host; $this->_port = $port; $this->_timeout = $timeout; $this->_cache =& new Memcache(); if (!$this->_cache->connect($this->_host, $this->_port)) { // dont use fatal here since we can go in an infinite loop echo 'Could not connect to Memcached server'; exit; } }
/** * Attempt to connect to the SMTP server. * * @param int $timeout The timeout value (in seconds) for the * socket connection attempt. * @param bool $persistent Should a persistent socket connection * be used? * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @since 1.0 */ public function connect($timeout = null, $persistent = false) { $this->greeting = null; $result = $this->socket->connect($this->host, $this->port, $persistent, $timeout, $this->socket_options); if (PEAR::isError($result)) { return PEAR::raiseError('Failed to connect socket: ' . $result->getMessage()); } /* * Now that we're connected, reset the socket's timeout value for * future I/O operations. This allows us to have different socket * timeout values for the initial connection (our $timeout parameter) * and all other socket operations. */ if ($this->timeout > 0) { if (PEAR::isError($error = $this->setTimeout($this->timeout))) { return $error; } } if (PEAR::isError($error = $this->parseResponse(220))) { return $error; } /* Extract and store a copy of the server's greeting string. */ list(, $this->greeting) = $this->getResponse(); if (PEAR::isError($error = $this->negotiate())) { return $error; } return true; }
public function update() { if ($this->server->needReconnect and $this->connected) { $this->connected = false; $this->server->needReconnect = false; } if ($this->connected) { $err = socket_last_error($this->socket->getSocket()); socket_clear_error($this->socket->getSocket()); if ($err == 10057 or $err == 10054) { $this->server->getLogger()->error("Synapse connection has disconnected unexpectedly"); $this->connected = false; $this->server->setConnected(false); } else { $data = @socket_read($this->socket->getSocket(), 65535, PHP_BINARY_READ); if ($data != "") { $this->receiveBuffer .= $data; } } } else { if (($time = microtime(true)) - $this->lastCheck >= 3) { //re-connect $this->server->getLogger()->notice("Trying to re-connect to Synapse Server"); if ($this->socket->connect()) { $this->connected = true; @socket_getpeername($this->socket->getSocket(), $address, $port); $this->ip = $address; $this->port = $port; $this->server->setConnected(true); $this->server->setNeedAuth(true); } $this->lastCheck = $time; } } }
/** * Constructs a new ezcCacheMemcacheBackend object. * * For options for this backend see {@link ezcCacheStorageMemcacheOptions}. * * @throws ezcBaseExtensionNotFoundException * If the PHP memcache and zlib extensions are not installed. * @throws ezcCacheMemcacheException * If the connection to the Memcache host did not succeed. * * @param array(string=>mixed) $options */ public function __construct(array $options = array()) { if (!ezcBaseFeatures::hasExtensionSupport('memcache')) { throw new ezcBaseExtensionNotFoundException('memcache', null, "PHP does not have Memcache support."); } if (!ezcBaseFeatures::hasExtensionSupport('zlib')) { throw new ezcBaseExtensionNotFoundException('zlib', null, "PHP not configured with --with-zlib."); } $this->options = new ezcCacheStorageMemcacheOptions($options); $this->connectionIdentifier = $this->options->host . ':' . $this->options->port; if (!isset(self::$connections[$this->connectionIdentifier])) { self::$connections[$this->connectionIdentifier] = new Memcache(); // Currently 0 backends use the connection self::$connectionCounter[$this->connectionIdentifier] = 0; } $this->memcache = self::$connections[$this->connectionIdentifier]; // Now 1 backend uses it self::$connectionCounter[$this->connectionIdentifier]++; if ($this->options->persistent === true) { if (!@$this->memcache->pconnect($this->options->host, $this->options->port, $this->options->ttl)) { throw new ezcCacheMemcacheException('Could not connect to Memcache using a persistent connection.'); } } else { if (!@$this->memcache->connect($this->options->host, $this->options->port, $this->options->ttl)) { throw new ezcCacheMemcacheException('Could not connect to Memcache.'); } } $this->memcache->setCompressThreshold(self::COMPRESS_THRESHOLD); }
/** * Connects to a database server * * @return bool - If the connection was successful. */ public function connect() { if ($this->protocol) { return true; } $this->socket->connect(); $this->protocol = new Protocol($this->socket); return true; }
/** * 返回redis链接资源 * @return unknown */ function getRedis() { if (empty($this->redis) || !$this->redis->info()) { $this->redis = new \Redis(); $redisConfig = \Config\Redis::getConfig(); $res = $this->redis->connect($redisConfig['host'], $redisConfig['port']); if (empty($res)) { echo "connect Redis failed!\n"; } } return $this->redis; }
/** * Attempt to connect to the SMTP server. * * @param int $timeout The timeout value (in seconds) for the * socket connection. * @param bool $persistent Should a persistent socket connection * be used? * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function connect($timeout = null, $persistent = false) { $result = $this->_socket->connect($this->host, $this->port, $persistent, $timeout); if (PEAR::isError($result)) { return new PEAR_Error('Failed to connect socket: ' . $result->getMessage()); } if (PEAR::isError($error = $this->_parseResponse(220))) { return $error; } if (PEAR::isError($error = $this->_negotiate())) { return $error; } return true; }
/** * Attempt to connect to the IMAP server. * * @param string $host Hostname of the IMAP server * @param int $port Port of the IMAP server (default = 143) * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function cmdConnect($host = 'localhost', $port = 143) { if ($this->_connected) { return new PEAR_Error('already connected, logout first!'); } if (PEAR::isError($error = $this->_socket->connect($host, $port, null, $this->_timeout, $this->_streamContextOptions))) { return $error; } if (PEAR::isError($this->_getRawResponse())) { return new PEAR_Error('unable to open socket'); } $this->_connected = true; return true; }
/** * Attempt to connect to the IMAP server. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function cmdConnect($host = "localhost", $port = 143) { if ($this->_connected) { return new PEAR_Error('already connected, logout first!'); } if (PEAR::isError($this->_socket->connect($host, $port))) { return new PEAR_Error('unable to open socket'); } if (PEAR::isError($this->_getRawResponse())) { return new PEAR_Error('unable to open socket'); } $this->_connected = true; return true; }
/** * Sets up the environment for each test method * * @return void * @access public */ public function startTest() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } ConnectionManager::create('mongo_test', $this->_config); $this->Mongo = new MongodbSource($this->_config); $this->Post = ClassRegistry::init('Post'); $this->Post->setDataSource('mongo_test'); $this->mongodb =& ConnectionManager::getDataSource($this->Post->useDbConfig); $this->mongodb->connect(); $this->dropData(); }
/** * Attempt to connect to the IMAP server. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function cmdConnect($host = "localhost", $port = 143) { if ($this->_connected) { return new PEAR_Error('already connected, logout first!'); } $result = $this->_socket->connect($host, $port, false, 10); if (PEAR::isError($result)) { return PEAR::raiseError('Failed to connect socket: ' . $result->getMessage()); } if (PEAR::isError($this->_getRawResponse())) { return new PEAR_Error('unable to open socket'); } $this->_connected = true; return true; }
/** * This function generates the FTP-connection * * @access public * @param string $host (optional) The hostname * @param int $port (optional) The port * @return mixed True on success, otherwise Jaws_Error */ function connect($host = null, $port = null) { if (isset($host)) { $this->_host = $host; } if (isset($port)) { $this->_port = $port; } $this->_ftp->setHostname($this->_host); $this->_ftp->setPort($this->_port); $res = $this->_ftp->connect(); if (PEAR::isError($res)) { return new Jaws_Error('Error while connecting to server ' . $this->_host . ' on ' . $this->_port . '.', __FUNCTION__); } return true; }
/** * Attempt to connect to the SMTP server. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public */ function connect() { include_once 'Net/Socket.php'; if (PEAR::isError($this->socket = new Net_Socket())) { return new PEAR_Error('unable to create a socket object'); } if (PEAR::isError($this->socket->connect($this->host, $this->port))) { return new PEAR_Error('unable to open socket'); } if (PEAR::isError($this->validateResponse('220'))) { return new PEAR_Error('smtp server not 220 ready'); } if (!$this->identifySender()) { return new PEAR_Error('unable to identify smtp server'); } return true; }
/** * Attempt to connect to the IMAP server. * * @param string $host Hostname of the IMAP server * @param int $port Port of the IMAP server (default = 143) * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function cmdConnect($host = 'localhost', $port = 143) { if ($this->_connected) { return new PEAR_Error('already connected, logout first!'); } if (PEAR::isError($error = $this->_socket->connect($host, $port, null, $this->_timeout, $this->_streamContextOptions))) { return $error; } if ($port == 993) { if (!$this->_socket->enableCrypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { return new PEAR_Error('Failed to set crypto'); } } if (PEAR::isError($this->_getRawResponse())) { return new PEAR_Error('unable to open socket'); } $this->_connected = true; return true; }
/** * 打开到服务端的连接 * @return void */ protected function openConnection() { $address = self::$addressArray[array_rand(self::$addressArray)]; if (self::$useSwoole) { $address = explode(':', $address); $this->swooleClient = new swoole_client(SWOOLE_SOCK_TCP); $this->swooleClient->set($this->swooleClientSets); if (!$this->swooleClient->connect($address[0], $address[1], self::TIME_OUT)) { exit("connect failed. Error: {$this->swooleClient->errCode}\n"); } } else { $this->connection = stream_socket_client($address, $err_no, $err_msg); if (!$this->connection) { throw new Exception("can not connect to {$address} , {$err_no}:{$err_msg}"); } stream_set_blocking($this->connection, true); stream_set_timeout($this->connection, self::TIME_OUT); } }
/** * Connect to the database. */ function connect() { $database = $this->config['database']['type']; require_once $database . '.php'; $this->db = new $database(); if (isset($this->config['database']['username']) && isset($this->config['database']['password'])) { if (!$this->db->connect($this->config['database'])) { trigger_error('Could not connect to server', E_USER_ERROR); } } elseif (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $this->config['database']['username'] = $_SERVER['PHP_AUTH_USER']; $this->config['database']['password'] = $_SERVER['PHP_AUTH_PW']; if (!$this->db->connect($this->config['database'])) { $this->unauthorized(); exit; } } else { $this->unauthorized(); exit; } }
/** * Constructor * * @param array $config an array of configuration params * * @return \CRM_Utils_Cache_Memcache */ function __construct($config) { if (isset($config['host'])) { $this->_host = $config['host']; } if (isset($config['port'])) { $this->_port = $config['port']; } if (isset($config['timeout'])) { $this->_timeout = $config['timeout']; } if (isset($config['prefix'])) { $this->_prefix = $config['prefix']; } $this->_cache = new Memcache(); if (!$this->_cache->connect($this->_host, $this->_port)) { // dont use fatal here since we can go in an infinite loop echo 'Could not connect to Memcached server'; CRM_Utils_System::civiExit(); } }
/** * Constructor * * @param array $config * An array of configuration params. * * @return \CRM_Utils_Cache_Redis */ public function __construct($config) { if (isset($config['host'])) { $this->_host = $config['host']; } if (isset($config['port'])) { $this->_port = $config['port']; } if (isset($config['timeout'])) { $this->_timeout = $config['timeout']; } if (isset($config['prefix'])) { $this->_prefix = $config['prefix']; } $this->_cache = new Redis(); if (!$this->_cache->connect($this->_host, $this->_port)) { // dont use fatal here since we can go in an infinite loop echo 'Could not connect to redisd server'; CRM_Utils_System::civiExit(); } $this->_cache->auth(CIVICRM_DB_CACHE_PASSWORD); }
/** * Attempt to connect to the IMAP server. * * @param string $host Hostname of the IMAP server * @param int $port Port of the IMAP server (default = 143) * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function cmdConnect($host = 'localhost', $port = 143) { if ($this->_connected) { return new PEAR_Error('already connected, logout first!'); } $error = $this->_socket->connect($host, $port, null, $this->_timeout, $this->_streamContextOptions); if ($error instanceof PEAR_Error) { return $error; } /* // ERP-modification: Creates more problems then it fixes so we disable it if ($port == 993) { if (!$this->_socket->enableCrypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { return new PEAR_Error('Failed to set crypto'); } } */ if ($this->_getRawResponse() instanceof PEAR_Error) { return new PEAR_Error('unable to open socket'); } $this->_connected = true; return true; }
/** * Attempt to connect to the SMTP server. * * @param int $timeout The timeout value (in seconds) for the * socket connection. * @param bool $persistent Should a persistent socket connection * be used? * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function connect($timeout = null, $persistent = false) { $this->_greeting = null; $result = $this->_socket->connect($this->host, $this->port, $persistent, $timeout); if (PEAR::isError($result)) { return PEAR::raiseError('Failed to connect socket: ' . $result->getMessage()); } if (PEAR::isError($error = $this->_parseResponse(220))) { return $error; } /* Extract and store a copy of the server's greeting string. */ list(, $this->_greeting) = $this->getResponse(); if (PEAR::isError($error = $this->_negotiate())) { return $error; } return true; }
/** * Sends out email via SMTP * * @return bool Success * @access private */ function __smtp() { App::import('Core', array('Socket')); $this->__smtpConnection =& new CakeSocket(array_merge(array('protocol' => 'smtp'), $this->smtpOptions)); if (!$this->__smtpConnection->connect()) { $this->smtpError = $this->__smtpConnection->lastError(); return false; } elseif (!$this->__smtpSend(null, '220')) { return false; } if (!$this->__smtpSend('HELO cake', '250')) { return false; } if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) { if (!$this->__smtpSend('AUTH LOGIN', '334')) { return false; } if (!$this->__smtpSend(base64_encode($this->smtpOptions['username']), '334')) { return false; } if (!$this->__smtpSend(base64_encode($this->smtpOptions['password']), '235')) { return false; } } if (!$this->__smtpSend('MAIL FROM: ' . $this->__formatAddress($this->from, true))) { return false; } if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) { return false; } foreach ($this->cc as $cc) { if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) { return false; } } foreach ($this->bcc as $bcc) { if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($bcc, true))) { return false; } } if (!$this->__smtpSend('DATA', '354')) { return false; } $header = implode("\r\n", $this->__header); $message = implode("\r\n", $this->__message); if (!$this->__smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) { return false; } $this->__smtpSend('QUIT', false); $this->__smtpConnection->disconnect(); return true; }
/** * Sends out email via SMTP * * @return bool Success * @access private */ private function __smtp() { App::import('Core', array('CakeSocket')); $this->__smtpConnection = new CakeSocket(array_merge(array('protocol' => 'smtp'), $this->smtpOptions)); if (!$this->__smtpConnection->connect()) { $this->smtpError = $this->__smtpConnection->lastError(); return false; } elseif (!$this->__smtpSend(null, '220')) { return false; } $httpHost = env('HTTP_HOST'); if (isset($this->smtpOptions['client'])) { $host = $this->smtpOptions['client']; } elseif (!empty($httpHost)) { $host = $httpHost; } else { $host = 'localhost'; } if (!$this->__smtpSend("HELO {$host}", '250')) { return false; } if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) { $authRequired = $this->__smtpSend('AUTH LOGIN', '334|503'); if ($authRequired == '334') { if (!$this->__smtpSend(base64_encode($this->smtpOptions['username']), '334')) { return false; } if (!$this->__smtpSend(base64_encode($this->smtpOptions['password']), '235')) { return false; } } elseif ($authRequired != '503') { return false; } } if (!$this->__smtpSend('MAIL FROM: ' . $this->__formatAddress($this->from, true))) { return false; } if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) { return false; } foreach ($this->cc as $cc) { if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) { return false; } } foreach ($this->bcc as $bcc) { if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($bcc, true))) { return false; } } if (!$this->__smtpSend('DATA', '354')) { return false; } $header = implode("\r\n", $this->__header); $message = implode("\r\n", $this->__message); if (!$this->__smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) { return false; } $this->__smtpSend('QUIT', false); $this->__smtpConnection->disconnect(); return true; }
/** * @throws CredisException * @return Credis_Client */ public function connect() { if ($this->connected) { return $this; } if ($this->standalone) { $flags = STREAM_CLIENT_CONNECT; $remote_socket = $this->port === NULL ? 'unix://' . $this->host : 'tcp://' . $this->host . ':' . $this->port; if ($this->persistent) { if ($this->port === NULL) { // Unix socket throw new CredisException('Persistent connections to UNIX sockets are not supported in standalone mode.'); } $remote_socket .= '/' . $this->persistent; $flags = $flags | STREAM_CLIENT_PERSISTENT; } $result = $this->redis = @stream_socket_client($remote_socket, $errno, $errstr, $this->timeout !== null ? $this->timeout : 2.5, $flags); } else { if (!$this->redis) { $this->redis = new Redis(); } $result = $this->persistent ? $this->redis->pconnect($this->host, $this->port, $this->timeout, $this->persistent) : $this->redis->connect($this->host, $this->port, $this->timeout); } // Use recursion for connection retries if (!$result) { $this->connectFailures++; if ($this->connectFailures <= $this->maxConnectRetries) { return $this->connect(); } $failures = $this->connectFailures; $this->connectFailures = 0; throw new CredisException("Connection to Redis failed after {$failures} failures." . (isset($errno) && isset($errstr) ? "Last Error : ({$errno}) {$errstr}" : "")); } $this->connectFailures = 0; $this->connected = TRUE; // Set read timeout if ($this->readTimeout) { $this->setReadTimeout($this->readTimeout); } if ($this->authPassword !== null) { $this->auth($this->authPassword); } if ($this->selectedDb !== 0) { $this->select($this->selectedDb); } return $this; }
/** * Connect to the server * * @param optional string $host The adress of the NNTP-server to connect to, defaults to 'localhost'. * @param optional int $port The port number to connect to, defaults to 119. * * @return mixed (bool) true on success or (object) pear_error on failure * @access public */ function connect($host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST, $port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT) { if ($this->isConnected()) { return PEAR::throwError('Already connected, disconnect first!', null); } // Open Connection $R = @$this->_socket->connect($host, $port, false, 15); if (PEAR::isError($R)) { return PEAR::throwError('Could not connect to the server', null, $R->getMessage()); } // Retrive the server's initial response. $response = $this->_getStatusResponse(); if (PEAR::isError($response)) { return $response; } switch ($response) { case 200: // Posting allowed // TODO: Set some variable return true; break; case 201: // Posting NOT allowed // TODO: Set some variable return true; break; case 502: // 'access restriction or permission denied' return PEAR::throwError('Server refused connection', $response, $this->currentStatusResponse()); break; default: return PEAR::throwError('Unidentified response code', $response, $this->currentStatusResponse()); } }
/** * @throws CredisException */ public function connect() { if ($this->connected) { return; } if (preg_match('#^(tcp|unix)://(.*)$#', $this->host, $matches)) { if ($matches[1] == 'tcp') { $hostParts = explode(':', $matches[2], 2); $this->host = $hostParts[0]; $this->port = (int) (isset($hostParts[1]) ? $hostParts[1] : '6379'); } else { $this->host = $matches[2]; } } if ($this->standalone) { if (substr($this->host, 0, 1) == '/') { $remote_socket = 'unix://' . $this->host; $this->port = null; } else { $remote_socket = 'tcp://' . $this->host . ':' . $this->port; } #$this->redis = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout); $this->redis = @stream_socket_client($remote_socket, $errno, $errstr, $this->timeout); if (!$this->redis) { throw new CredisException("Connection to {$this->host}" . ($this->port ? ":{$this->port}" : '') . " failed: {$errstr} ({$errno})"); } } else { $this->redis = new Redis(); if (substr($this->host, 0, 1) == '/') { $result = $this->redis->connect($this->host, null, $this->timeout); } else { $result = $this->redis->connect($this->host, $this->port, $this->timeout); } if (!$result) { throw new CredisException("An error occurred connecting to Redis."); } } $this->connected = TRUE; }
/** * Handles connecting to the server and checks the response validity. * * @param string $host Hostname of server. * @param string $port Port of server. * @param array $options List of options to pass to * stream_context_create(). * @param boolean $useTLS Use TLS if available. * * @return boolean True on success, PEAR_Error otherwise. */ function connect($host, $port, $options = null, $useTLS = true) { $this->_data['host'] = $host; $this->_data['port'] = $port; $this->_useTLS = $useTLS; if (is_array($options)) { $this->_options = array_merge($this->_options, $options); } if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) { return PEAR::raiseError('Not currently in DISCONNECTED state', 1); } if (PEAR::isError($res = $this->_sock->connect($host, $port, false, 5, $options))) { return $res; } if ($this->_bypassAuth) { $this->_state = NET_SIEVE_STATE_TRANSACTION; } else { $this->_state = NET_SIEVE_STATE_AUTHORISATION; if (PEAR::isError($res = $this->_doCmd())) { return $res; } } // Explicitly ask for the capabilities in case the connection is // picked up from an existing connection. if (PEAR::isError($res = $this->_cmdCapability())) { return PEAR::raiseError('Failed to connect, server said: ' . $res->getMessage(), 2); } // Check if we can enable TLS via STARTTLS. if ($useTLS && !empty($this->_capability['starttls']) && function_exists('stream_socket_enable_crypto')) { if (PEAR::isError($res = $this->_startTLS())) { return $res; } } return true; }
/** * Sends out email via SMTP * * @return bool Success * @access private */ function _smtp() { App::import('Core', array('CakeSocket')); $defaults = array('host' => 'localhost', 'port' => 25, 'protocol' => 'smtp', 'timeout' => 30); $this->smtpOptions = array_merge($defaults, $this->smtpOptions); $this->_getSocket($this->smtpOptions); if (!$this->__smtpConnection->connect()) { $this->smtpError = $this->__smtpConnection->lastError(); return false; } elseif (!$this->_smtpSend(null, '220')) { return false; } $httpHost = env('HTTP_HOST'); if (isset($this->smtpOptions['client'])) { $host = $this->smtpOptions['client']; } elseif (!empty($httpHost)) { list($host) = explode(':', $httpHost); } else { $host = 'localhost'; } if (!$this->_smtpSend("EHLO {$host}", '250') && !$this->_smtpSend("HELO {$host}", '250')) { return false; } if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) { $authRequired = $this->_smtpSend('AUTH LOGIN', '334|503'); if ($authRequired == '334') { if (!$this->_smtpSend(base64_encode($this->smtpOptions['username']), '334')) { return false; } if (!$this->_smtpSend(base64_encode($this->smtpOptions['password']), '235')) { return false; } } elseif ($authRequired != '503') { return false; } } if (!$this->_smtpSend('MAIL FROM: ' . $this->_formatAddress($this->from, true))) { return false; } if (!is_array($this->to)) { $tos = array_map('trim', explode(',', $this->to)); } else { $tos = $this->to; } foreach ($tos as $to) { if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($to, true))) { return false; } } foreach ($this->cc as $cc) { if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($cc, true))) { return false; } } foreach ($this->bcc as $bcc) { if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($bcc, true))) { return false; } } if (!$this->_smtpSend('DATA', '354')) { return false; } $header = implode("\r\n", $this->__header); $message = implode("\r\n", $this->__message); if (!$this->_smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) { return false; } $this->_smtpSend('QUIT', false); $this->__smtpConnection->disconnect(); return true; }
protected function _initRFS($server) { App::import('Vendor', 'RFS', array('file' => 'RFS/FtpFactory.php')); $this->_rfsResource = FtpFactory::create($this->field('type')); $this->_rfsResource->connect($server['hostname'], $server['username'], $server['password'], $server['port']); }