Skip to content

Instantly share code, notes, and snippets.

@IlariExove
Created November 25, 2016 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlariExove/a8cfe7ef39569d3b4f0cc35dc53bb854 to your computer and use it in GitHub Desktop.
Save IlariExove/a8cfe7ef39569d3b4f0cc35dc53bb854 to your computer and use it in GitHub Desktop.
How to debug PHP cURL SSL/TLS parameters
<?php
$ch = curl_init('https://www.google.com/');
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_exec($ch);
curl_close($ch);
rewind($verbose);
$stderr_lines = explode("\n", stream_get_contents($verbose));
$tls_nego = array();
foreach($stderr_lines as $line)
{
if (preg_match_all('/^\* Connected to (.*) \(.* port (.*) \(.*$/', $line, $matches) != 0)
{
$server = $matches[1][0] . ':' . $matches[2][0];
}
if (preg_match_all('/^\* (.*) connection using (.*)$/', $line, $matches) != 0)
{
$tls_nego[$server] = array($matches[1][0], $matches[2][0]);
}
}
print_r($tls_nego);
@IlariExove
Copy link
Author

Array
(
    [www.google.com:443] => Array
        (
            [0] => TLS 1.2
            [1] => TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
        )

    [www.google.fi:443] => Array
        (
            [0] => TLS 1.2
            [1] => TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
        )

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment