Created
August 19, 2012 16:03
-
-
Save cboden/3395757 to your computer and use it in GitHub Desktop.
No Async SSL w/ PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN CERTIFICATE----- | |
MIIEFzCCAv+gAwIBAgIBADANBgkqhkiG9w0BAQQFADBqMQswCQYDVQQGEwJkZTEP | |
MA0GA1UECBMGSGVzc2VuMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBM | |
dGQxEzARBgNVBAcTCkRpbGxlbmJ1cmcxEjAQBgNVBAMTCTEyNy4wLjAuMTAeFw0x | |
MjA2MTYyMDE2MDhaFw0yMjA2MTQyMDE2MDhaMGoxCzAJBgNVBAYTAmRlMQ8wDQYD | |
VQQIEwZIZXNzZW4xITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDET | |
MBEGA1UEBxMKRGlsbGVuYnVyZzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkq | |
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAofA7J9eN5Q8pTrbHOBQC63gB4m6NPNjx | |
NZ302U5VK5SIkT8lYNk/uwY88C93jAgEBjgSk9IcLdzCRIay5UJmf92fSwZS+x+7 | |
V8nQyuMtQ+9uipX5nhFVAj1iGbO92McsuBb9ck1jQuNt5YZW1WsnGivh88vMiKBa | |
7eKnJZbgPjAShCL+WvZpCbWuhy6iUlb/ya0PUNZZNYAkznXarUB706rhLFKF2ikq | |
lVJnK9d1b/rifBQbHs2anOnKa6ZUUKoai/uOg/F7KpV83tsR5RWaHqy0vICgiG77 | |
qx8cBzKgnL14BFQ5AZWv6Rul9+snnJlpGhuNr7gc/iMD4RfEmJzIawIDAQABo4HH | |
MIHEMB0GA1UdDgQWBBQk4IptXfOI12nTkE1T4vvR8xw3gzCBlAYDVR0jBIGMMIGJ | |
gBQk4IptXfOI12nTkE1T4vvR8xw3g6Fup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adDDDicE2AH | |
PQo6dCCF67nR8H5+0/XBcQL65QAcPMdxt4dX4SCNPtJPop6cxj0/QTdby+S9Ws9x | |
RO1Psjt4WwPeFuoufbwP3dCgg87LeZRyuS5D7vfUMVI2OB7dzHaxXQ== | |
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(-1); | |
$clientContext = stream_context_create(array("ssl" => array( | |
'allow_self_signed' => true, | |
'verify_peer' => false | |
))); | |
$connection = stream_socket_client('ssl://localhost:4096', $errcode, $errstr, 2, STREAM_CLIENT_CONNECT, $clientContext); | |
stream_set_blocking($connection, 0); | |
if ($connection) { | |
echo "\n\n************\nConnected!\n\n"; | |
sleep(1); | |
echo stream_get_contents($connection); | |
} else { | |
echo "\n\nError occured:\n$errcode\n$errstr\n\n"; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(-1); | |
$sslOptions = array( | |
'local_cert' => __DIR__.'/certificate.pem', | |
'allow_self_signed' => true, | |
'verify_peer' => false | |
); | |
$serverContext = stream_context_create(array("ssl" => $sslOptions)); | |
$socket = stream_socket_server("ssl://127.0.0.1:4096", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $serverContext); | |
// Uncomment the following line to make the server asynchronous (and break everything): | |
//stream_set_blocking($socket, 0); | |
while ($conn = stream_socket_accept($socket)) { | |
fwrite($conn, "Hello encrypted world!\n"); | |
fclose($conn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment