Here is a simple PHP script that opens an SSL socket ready to send HTTP requests:
$ contextOptions = array ();
$ socketUrl = 'ssl: //google.com: 443';
$ streamContext = stream_context_create ($ contextOptions);
$ socket = stream_socket_client ($ socketUrl, $ errno, $ errstr, 30, STREAM_CLIENT_CONNECT, $ streamContext);
if (! $ socket || $ errno! == 0) {
var_dump ($ socket, $ errstr);
exit
}
var_dump ($ socket);
exit ('Socket created.');
This works - I just tested it, but the validity of the CA repository is not verified.
We can change that script to use PHP SSL context options :
$ contextOptions = array (
'ssl' => array (
'cafile' => 'C: \ xampp \ cacerts.pem',
'CN_match' => '* .google.com', // CN_match will only be checked if 'verify_peer' is set to TRUE. See https://bugs.php.net/bug.php?id=47030.
'verify_peer' => TRUE,
)
);
$ socketUrl = 'ssl: //google.com: 443';
$ streamContext = stream_context_create ($ contextOptions);
$ socket = stream_socket_client ($ socketUrl, $ errno, $ errstr, 30, STREAM_CLIENT_CONNECT, $ streamContext);
if (! $ socket || $ errno! == 0) {
var_dump ($ socket, $ errstr);
exit
}
var_dump ($ socket);
exit ('Socket created.');
As long as there is a cafile and has a valid CA, this example also works ...
... / CA? -, SSL- OS-, , script.
, Linux , "capath". Windows? ? , , , , , , PHP? ?