Menu

#86 SSL/HTTPS-requests don't work with PHP 5.6 (peer verification)

open
nobody
None
5
2019-04-24
2015-03-19
Uwe Hunfeld
No

A user reported that SSL/HTTPS-requests don't work anymore with PHP 5.6.

The reason is that peer-verification is enabled by default since PHP 5.6, and (somehow) the necessary local CA-certificate can't be located in the local environment (only in some environments?).

Also see http://php.net/manual/en/migration56.openssl.php

Discussion

  • Ahmed Jadelrab

    Ahmed Jadelrab - 2015-10-21

    Same problem here when I tried to crawl this link "https://graph.facebook.com/4/picture?width=378&height=378"

    It gave me this error message "Error connecting to https://graph.facebook.com: Host unreachable ()".

     
    • Anonymous

      Anonymous - 2018-04-09
      Post awaiting moderation.
  • Ahmed Jadelrab

    Ahmed Jadelrab - 2015-10-21

    I worte something before to solve SSL problem...

    $arrContextOptions=array(
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );
    
    $url = 'https://graph.facebook.com/4/picture?width=378&height=378';
    
        $imageUrl = file_get_contents($url, false, stream_context_create($arrContextOptions));
        $image = dirname(__file__).'/avatar/ .jpg';
        file_put_contents($image, $imageUrl);
    

    I hope it will help you.

     
  • Anonymous

    Anonymous - 2016-01-07

    I had the same problem and your solution worked for me. Thanks!

    I changed the code of PHPCrawlerHTTPRequest.class.php at line 547 to:

        $context = stream_context_create(array(
            'ssl' => array(
                'SNI_server_name' => $this->url_parts["host"],
                'verify_peer' => false,
                'verify_peer_name' => false,
            )
        ));
    
     
    • Anonymous

      Anonymous - 2016-04-01
       

      Last edit: Anonymous 2016-04-01
    • Ahmed Jadelrab

      Ahmed Jadelrab - 2016-04-01

      I am happy for help :)

       
  • Anonymous

    Anonymous - 2016-01-31

    Thanks, it worked now for ssl domains

     
  • Anonymous

    Anonymous - 2016-02-08

    Hi,
    I did not disable verifying peer_name, but as of PHP 5.6 "SNI_server_name" is deprecated and "peer_name" should be used instead (aacording to: http://php.net/manual/en/context.ssl.php ).
    I´ve forked the project on github. The following link points to my change, were I set the needed value for SSL via PHP_Version check:
    https://github.com/merzilla/phpcrawl/blob/fix-php56-ssl-problem/libs/PHPCrawlerHTTPRequest.class.php#L537

    HTH
    merzilla

     

    Last edit: Anonymous 2016-02-08
    • Anonymous

      Anonymous - 2016-03-30

      Thanks merzilla

      I can also confirm, that this worked for me (PHP 5.6.x / 7.x).

      NetHawk

       
  • Anonymous

    Anonymous - 2016-03-16

    Thanks for merzilla. I check your code and it work.

     
  • Anonymous

    Anonymous - 2019-04-24
    Post awaiting moderation.

Anonymous
Anonymous

Add attachments
Cancel