PHP Conference Kansai 2025

Dominios de Internet: TCP, UDP, SSL y TLS

ssl://, tls://, sslv2:// & sslv3://.

Nota: Si no se especifica ningún transporte, se utiliza 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

Los sockets del dominio de Internet utilizan un número de puerto además de la dirección del host. En el caso de fsockopen(), se especifica en el segundo parámetro y, por lo tanto, no tiene impacto en el formato del modo de transporte. Con stream_socket_client() y otras funciones de la misma familia, el número de puerto se especifica como un sufijo en la URL de transporte, identificado por el signo de dos puntos.

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

Nota: Dirección IPv6 y número de puerto
En el segundo ejemplo anterior, los ejemplos en IPv4 y los nombres de host son idénticos, pero las IPv6 se colocan entre corchetes, además de tener los dos puntos y el número de puerto: [fe80::1]. Esto permite distinguir los dos puntos utilizados en IPv6 y los dos puntos utilizados para delimitar el número de puerto.

Los modos ssl:// y tls:// (disponibles únicamente cuando el soporte OpenSSL está compilado con PHP) son extensiones de tcp:// que incluyen el cifrado SSL.

ssl:// intentará negociar una conexión SSL V2 o SSL V3, según las capacidades y las referencias del host remoto. sslv2:// y sslv3:// seleccionan explícitamente el protocolo.

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