How to solve Peer certificate CN not matching in PHP with CakePHP

If you are dealing with this error:

Error: stream_socket_client(): Peer certificate CN=`*.google.com' did not match expected CN=`*.youtube.com'

It's because PHP do not correctly verify peers and is not handling the wildcard matching for CN in a properly way, you can have a look to this two pull requests to have more information:

So, How do we solve this problem in our CakePHP project? just disable the ssl verify host in the HttpSocket like this:

$this->HttpSocket = new HttpSocket(array(
    'ssl_verify_host' => false
));