Dutch PHP Conference 2025 - Call For Papers

Інтернет: 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

Інтернет-сокетам потрібен номер порту на додачу до цільової адреси. У випадку 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:// (доступні, якщо PHP скомпільовано з підтримкою openssl) є розширеннями протоколу tcp://, які містять SSL-шифрування.

ssl:// спробує узгодити з’єднання SSL V2 або SSL V3 залежно від можливостей і налаштувань віддаленого хоста. sslv2:// і sslv3:// оберуть протокол SSL V2 або SSL V3 відповідно.

add a note

User Contributed Notes 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