Example #1
0
 /**
  * Connect to SMTP Server
  *
  * @return void
  * @throws SocketException
  */
 protected function _connect()
 {
     $this->_generateSocket();
     if (!$this->_socket->connect()) {
         throw new SocketException(__d('cake_dev', 'Unable to connect to SMTP server.'));
     }
     $this->_smtpSend(null, '220');
     if (isset($this->_config['client'])) {
         $host = $this->_config['client'];
     } elseif ($httpHost = env('HTTP_HOST')) {
         list($host) = explode(':', $httpHost);
     } else {
         $host = 'localhost';
     }
     try {
         $this->_smtpSend("EHLO {$host}", '250');
         if ($this->_config['tls']) {
             $this->_smtpSend("STARTTLS", '220');
             $this->_socket->enableCrypto('tls');
             $this->_smtpSend("EHLO {$host}", '250');
         }
     } catch (SocketException $e) {
         if ($this->_config['tls']) {
             throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.'));
         }
         try {
             $this->_smtpSend("HELO {$host}", '250');
         } catch (SocketException $e2) {
             throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection.'));
         }
     }
 }
Example #2
0
 /**
  * Получение списка worker-ов
  *
  * @param string $worker имя воркеров, параметры которого нам нужно получить
  * @return array массив доступных worker-ов с их загрузкой и тд
  */
 public function getWorkers($worker = null)
 {
     // получаем статистику по worker-ам
     \App::uses('CakeSocket', 'Network');
     $Socket = new \CakeSocket($this->_config['server']);
     $Socket->connect();
     $workers = array();
     // делаем 2 замера с интервалом в 1 секунду для получение точного результата
     for ($i = 0; $i <= 2; $i++) {
         $Socket->write("status\n");
         $content = $Socket->read(50000);
         $answers = explode("\n", trim($content));
         foreach ($answers as $string) {
             $temp = explode("\t", $string);
             $title = trim($temp[0]);
             if (strpos($title, 'restart') !== false || strpos($title, '.') !== false) {
                 continue;
             }
             if (!empty($workers[$title])) {
                 // тут нас интересует только макс. значение доступных worker-ов
                 $workers[$title][3] = intval($workers[$title][3]) < intval($temp[3]) ? $temp[3] : $workers[$title][3];
             } else {
                 $workers[$title] = $temp;
             }
         }
         sleep(1);
     }
     $Socket->disconnect();
     return $worker ? $workers[$worker] : $workers;
 }
Example #3
0
 /**
  * Connect
  *
  * @param string $host
  * @param integer $port
  * @return FtpSocket
  */
 public function connect($host = null, $port = null)
 {
     if (isset($host)) {
         $this->config['host'] = $host;
     }
     if (isset($port)) {
         $this->config['port'] = $port;
     }
     parent::connect();
     return $this;
 }
 /**
  * Test that protocol in the host doesn't cause cert errors.
  *
  * @return void
  */
 public function testConnectProtocolInHost()
 {
     $this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
     $configSslTls = array('host' => 'ssl://smtp.gmail.com', 'port' => 465, 'timeout' => 5);
     $socket = new CakeSocket($configSslTls);
     try {
         $socket->connect();
         $this->assertEquals('smtp.gmail.com', $socket->config['host']);
         $this->assertEquals('ssl', $socket->config['protocol']);
     } catch (SocketException $e) {
         $this->markTestSkipped('Cannot test network, skipping.');
     }
 }
Example #5
0
 /**
  * @brief set up the connection for the socket
  *
  * This method will connect to the server and wait for the welcome
  * message. It is the responsibility of the driver to authenticate
  * if that is needed.
  * 
  * @return bool was the login correct of not
  */
 public function login()
 {
     parent::connect();
     if (!parent::read(1024, 'isOk')) {
         $this->error('Server not responding, exiting');
         return false;
     }
     if (!$this->_getCapabilities()) {
         $this->error('Unable to get the sockets capabilities');
     }
     return true;
 }