Home » Php » php – OpenSSL SSL_read: Connection was reset

php – OpenSSL SSL_read: Connection was reset

Posted by: admin February 25, 2020 Leave a comment

Questions:

Hi guys can anyone help me please, here is a simple piece of code:

try {
        $ch = curl_init();

        if ($ch === false) {
            throw new Exception('failed to initialize');
        }

        $agent = "Mozilla/5.0 (X11; U; Linux i686; en-US) 
                  AppleWebKit/532.4 (KHTML, like Gecko) 
                  Chrome/4.0.233.0 Safari/532.4";
        $referer = "http://www.google.com/";

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIE, $cookies);
        curl_setopt($ch, CURLOPT_REFERER, $referer);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        $result = curl_exec($ch);

        if ($result === false) {
            throw new Exception(curl_error($ch), curl_errno($ch));
        }


        curl_close($ch);
            } catch(Exception $e) {

            trigger_error(sprintf(
            'Curl failed with error #%d: %s',
            $e->getCode(), $e->getMessage()),
            E_USER_ERROR);

}

curl_exec() always returns false. i checked the error using curl_error(), (OpenSSL SSL_read: Connection was reset)

How to&Answers: