【问题标题】:PHP - Unexpected behaviour when added SSL to TCP socketPHP - 将 SSL 添加到 TCP 套接字时出现意外行为
【发布时间】:2014-08-24 09:17:21
【问题描述】:

我开发了 PHP WebSocket 服务器,它使用 HTTP 协议进行握手。一切正常。
当我想添加 SSL 层时,问题就开始了。当我启用它时,HTTP 帧会分成两部分到达 - 我需要调用两次读取函数来读取第二部分:

  1. HTTP 标头 (G) 的首字母
  2. 标题的其余部分

没有 SSL 一切正常。我尝试了很多修改,但没有结果。 有什么想法吗?

读取函数列表:

protected function read($toRead = 1400) {
  $return = "";
  for (;;) {
      if ($toRead < Config::$socket['chunk_size']) {
          $length = $toRead;
      } else {
          $length = Config::$socket['chunk_size'];
      }
      $sData = fread($this->socket, $length);
      if ($sData == false) return false;
      $toRead = $toRead - $length;
      $return .= $sData;
      if ($toRead == 0) break;
  }
  var_dump($return);
    return $return;
}

SSL上下文:

protected function createSSLContext() {
    $context = stream_context_create();
    if (Config::$ssl['switch']) {
        stream_context_set_option($context, 'ssl', 'local_cert', Config::$ssl['filename']);     
        stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
        stream_context_set_option($context, 'ssl', 'verify_peer', false);
        if (isset(Config::$ssl['passphrase'])) { 
            stream_context_set_option($context, 'ssl', 'passphrase', Config::$ssl['passphrase']);
        }
    }
    $this->context = $context;
}

【问题讨论】:

  • 完全没有错误显示?
  • 您是否启用了“显示错误”?
  • 是的,ini_set('display_errors', 'On');

标签: php sockets ssl tcp websocket


【解决方案1】:

我一直在使用 stunnel,但仍然找不到问题的解决方案。

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    相关资源
    最近更新 更多