2011-01-20 71 views
5


我的proplem是我的服务器端代码(书面的PHP)中有一个开放的套接字,我需要转换此套接字使用TLS,在通过它之前协商和解码流到已有的无需加密的清晰流的代码。 什么是归档这个最简单的解决方案?TLS与PHP服务器套接字

回答

3

PHP支持使用流上下文进行TLS/SSL侦听。像这样的东西应该工作:

$listenstr = "tls://0.0.0.0:1234"; 

$ctx=stream_context_create(array('ssl'=>array(
    "local_cert"=>"mycertandkey.pem", 
    "passphrase"=>"badpassphrase" 
))); 

$s = stream_socket_server($listenstr,$errno,$errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN,$ctx); 
$conn = stream_socket_accept($s); 
// do stuff with your new connection here