PHP 8.4.1 Released!

Internet 域:TCP,UDP,SSL 和 TLS

ssl://tls://sslv2:// & sslv3://

注意: 如果没有指定传输器,则假设是 tcp://

  • 127.0.0.1
  • fe80::1
  • www.example.com
  • tcp://127.0.0.1
  • tcp://fe80::1
  • tcp://www.example.com
  • udp://www.example.com
  • ssl://www.example.com
  • sslv2://www.example.com
  • sslv3://www.example.com
  • tls://www.example.com

Internet 域套接字在目标地址中还期望有一个端口号。在 fsockopen() 中在第二个参数中指定,这样就不会影响传输器的 URL。然而在 stream_socket_client() 和相关的函数中是用传统的 URL,端口号在传输器 URL 后面以冒号分隔而指定。

  • tcp://127.0.0.1:80
  • tcp://[fe80::1]:80
  • tcp://www.example.com:80

注意: 带端口号的 IPv6 数字地址
在上面的第二个例子中,IPv4 和主机名的例子只加了一个冒号和端口号,但 IPv6 的地址被放在方括号中: [fe80::1]。这是为了将 IPv6 地址中的冒号和用来分隔端口号的冒号区别开来。

ssl://tls:// 传输器(仅在 openssl 支持已编译入 PHP 后可用)是 tcp:// 传输器加入 SSL 加密后的扩展。

ssl:// 将根据远程服务器的兼容性和参数设置尝试与之建立 SSL V2 或 SSL V3 链接 sslv2://sslv3:// 将明确的选择 SSL V2 或 SSL V3 协议进行连接。

添加备注

用户贡献的备注 2 notes

up
16
christian at lantian dot eu
11 years ago
@pablo dot livardo : I think that the problem you found is caused by the difference between the client/server encryption methods used.

The 465 port is used for SMTPS, and the server starts the encryption immediately it receives your connection. So, your code will work.

The 587 port is used for Submission (MSA or Mail Submission Agent) which works like the port 25. The server accepts your connection and doesn't activate the encryption. If you want an encrypted connection on the port 587, you must connect on it without encryption, you must start to dialog with the server (with EHLO) and after that you must ask the server to start the encrypted connection using the STARTTLS command. The server starts the encryption and now you can start as well the encryption on your client.

So, in few words, you can not use :

<?php $fp = fsockopen("tls://mail.example.com", 587, $errno, $errstr); ?>

but you can use:

<?php $fp = stream_socket_client("mail.example.com:587", $errno, $errstr); ?>

and after you send the STARTTLS command, you can enable the crypto:

<?php stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); ?>

P.S. My previous note on this page was totally wrong, so I ask the php.net admin to remove it.

:)
up
6
stefan at example dot com
14 years ago
Actually, PHP is very able to start with an unencrypted connection and then switch to an encrypted one - refer to http://php.net/stream_socket_enable_crypto .
To Top