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

FWRITE(3)								 1								 FWRITE(3)

fwrite - Binary-safe file write

SYNOPSIS
int fwrite (resource $handle, string $string, [int $length]) DESCRIPTION
fwrite(3) writes the contents of $string to the file stream pointed to by $handle. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $string - The string that is to be written. o $length - If the $length argument is given, writing will stop after $length bytes have been written or the end of $string is reached, whichever comes first. Note that if the $length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from $string. RETURN VALUES
fwrite(3) returns the number of bytes written, or FALSE on error. NOTES
Note Writing to a network stream may end before the whole string is written. Return value of fwrite(3) may be checked: <?php function fwrite_stream($fp, $string) { for ($written = 0; $written < strlen($string); $written += $fwrite) { $fwrite = fwrite($fp, substr($string, $written)); if ($fwrite === false) { return $written; } } return $written; } ?> Note On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen(3) mode parameter. Note If $handle was fopen(3)ed in append mode, fwrite(3)s are atomic (unless the size of $string exceeds the filesystem's block size, on some platforms, and as long as the file is on a local filesystem). That is, there is no need to flock(3) a resource before calling fwrite(3); all of the data will be written without interruption. Note If writing twice to the file pointer, then the data will be appended to the end of the file content: <?php $fp = fopen('data.txt', 'w'); fwrite($fp, '1'); fwrite($fp, '23'); fclose($fp); // the content of 'data.txt' is now 123 and not 23! ?> EXAMPLES
Example #1 A simple fwrite(3) example <?php $filename = 'test.txt'; $somecontent = "Add this to the file "; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> SEE ALSO
fread(3), fopen(3), fsockopen(3), popen(3), file_get_contents(3). PHP Documentation Group FWRITE(3)
Man Page