CakeFest 2024: The Official CakePHP Conference

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() の場合、これは 2 番目の パラメータとして指定するので、トランスポートの URL には影響を与えません。 しかし、stream_socket_client() および関連する関数では 伝統的な URL を使用します。この場合、ポート番号はトランスポート URL の 後にコロンで区切ってつなげます。

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

注意: IPv6 数値アドレスとポート番号
IPv4 やホスト名形式の例では、ポート番号はアドレスやホスト名の直後に コロンでつながっていますが、上の 2 番目の例では 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 4 notes

up
16
christian at lantian dot eu
10 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
13 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 .
up
-12
christian at lantian dot eu
10 years ago
@pablo dot livardo : I think that the problem you found is caused by the difference between the client/server encryption methods used.

You tried to access the port 587 using TLS encryption, but the server uses the SSLv3 encryption on this port.

You can communicate with the Google server on port 465 because on this port the communication is encrypted using TLS and your client is configured to recognize the TLS.

So, if you want to connect on the Google server over the port 587, you simply must write:

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

instead of:

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

:)
up
-17
pablo dot livardo at gmail dot com
14 years ago
I've been having a problem with a TLS connection.

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

Which gives me an error of:

SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

I believe this is caused by PHP not being able to start with an unencrypted connection and then switch to encryption even though the functionality is built into OpenSSL.

For Google Mail users you can avoid this by using port 465 instead of 587.
To Top