Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

stream_socket_enable_crypto(3) [php man page]

STREAM_SOCKET_ENABLE_CRYPTO(3)						 1					    STREAM_SOCKET_ENABLE_CRYPTO(3)

stream_socket_enable_crypto - Turns encryption on/off on an already connected socket

SYNOPSIS
mixed stream_socket_enable_crypto (resource $stream, bool $enable, [int $crypto_type], [resource $session_stream]) DESCRIPTION
Enable or disable encryption on the stream. Once the crypto settings are established, cryptography can be turned on and off dynamically by passing TRUE or FALSE in the $enable param- eter. PARAMETERS
o $stream - The stream resource. o $enable - Enable/disable cryptography on the stream. o $crypto_type - Setup encryption on the stream. Valid methods are o STREAM_CRYPTO_METHOD_SSLv2_CLIENT o STREAM_CRYPTO_METHOD_SSLv3_CLIENT o STREAM_CRYPTO_METHOD_SSLv23_CLIENT o STREAM_CRYPTO_METHOD_TLS_CLIENT o STREAM_CRYPTO_METHOD_SSLv2_SERVER o STREAM_CRYPTO_METHOD_SSLv3_SERVER o STREAM_CRYPTO_METHOD_SSLv23_SERVER o STREAM_CRYPTO_METHOD_TLS_SERVER If omitted, the $crypto_type context option on the stream's SSL context will be used instead. o $session_stream - Seed the stream with settings from $session_stream. RETURN VALUES
Returns TRUE on success, FALSE if negotiation has failed or 0 if there isn't enough data and you should try again (only for non-blocking sockets). CHANGELOG
+--------+------------------------------------+ |Version | | | | | | | Description | | | | +--------+------------------------------------+ | 5.6.0 | | | | | | | The $crypto_type is now optional. | | | | +--------+------------------------------------+ EXAMPLES
Example #1 stream_socket_enable_crypto(3) example <?php $fp = stream_socket_client("tcp://myproto.example.com:31337", $errno, $errstr, 30); if (!$fp) { die("Unable to connect: $errstr ($errno)"); } /* Turn on encryption for login phase */ stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); fwrite($fp, "USER god "); fwrite($fp, "PASS secret "); /* Turn off encryption for the rest */ stream_socket_enable_crypto($fp, false); while ($motd = fgets($fp)) { echo $motd; } fclose($fp); ?> The above example will output something similar to: SEE ALSO
"OpenSSL Functions", "List of Supported Socket Transports". PHP Documentation Group STREAM_SOCKET_ENABLE_CRYPTO(3)

Check Out this Related Man Page

STREAM_SOCKET_CLIENT(3) 						 1						   STREAM_SOCKET_CLIENT(3)

stream_socket_client - Open Internet or Unix domain socket connection

SYNOPSIS
resource stream_socket_client (string $remote_socket, [int &$errno], [string &$errstr], [float $timeout = ini_get("default_socket_time- out")], [int $flags = STREAM_CLIENT_CONNECT], [resource $context]) DESCRIPTION
Initiates a stream or datagram connection to the destination specified by $remote_socket. The type of socket created is determined by the transport specified using standard URL formatting: transport://target. For Internet Domain sockets (AF_INET) such as TCP and UDP, the tar- get portion of the $remote_socket parameter should consist of a hostname or IP address followed by a colon and a port number. For Unix domain sockets, the $target portion should point to the socket file on the filesystem. Note The stream will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking(3). PARAMETERS
o $remote_socket - Address to the socket to connect to. o $errno - Will be set to the system level error number if connection fails. o $errstr - Will be set to the system level error message if the connection fails. o $timeout - Number of seconds until the connect() system call should timeout. Note This parameter only applies when not making asynchronous connection attempts. Note To set a timeout for reading/writing data over the socket, use the stream_set_timeout(3), as the $timeout only applies while making connecting the socket. o $flags - Bitmask field which may be set to any combination of connection flags. Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default), STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT. o $context - A valid context resource created with stream_context_create(3). RETURN VALUES
On success a stream resource is returned which may be used together with the other file functions (such as fgets(3), fgetss(3), fwrite(3), fclose(3), and feof(3)), FALSE on failure. ERRORS
/EXCEPTIONS On failure the $errno and $errstr arguments will be populated with the actual system level error that occurred in the system-level con- nect() call. If the value returned in $errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the $errno and $errstr arguments will always be passed by reference. EXAMPLES
Example #1 stream_socket_client(3) example <?php $fp = stream_socket_client("tcp://www.example.com:80", $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br /> "; } else { fwrite($fp, "GET / HTTP/1.0 Host: www.example.com Accept: */* "); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); } ?> Example #2 Using UDP connection Retrieving the day and time from the UDP service "daytime" (port 13) on localhost. <?php $fp = stream_socket_client("udp://127.0.0.1:13", $errno, $errstr); if (!$fp) { echo "ERROR: $errno - $errstr<br /> "; } else { fwrite($fp, " "); echo fread($fp, 26); fclose($fp); } ?> NOTES
Warning UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data. Note When specifying a numerical IPv6 address (e.g. fe80::1), you must enclose the IP in square brackets--for example, tcp://[fe80::1]:80. Note Depending on the environment, the Unix domain or the optional connect timeout may not be available. A list of available transports can be retrieved using stream_get_transports(3). See "List of Supported Socket Transports" for a list of built in transports. SEE ALSO
stream_socket_server(3), stream_set_blocking(3), stream_set_timeout(3), stream_select(3), fgets(3), fgetss(3), fwrite(3), fclose(3), feof(3), "cURL Functions". PHP Documentation Group STREAM_SOCKET_CLIENT(3)
Man Page