2 votes

Problem cURL error 35: Unknown SSL protocol using Firebase PHP API?

My problem is that I am trying to access my realtime database hosted on Firebase using their api rest kreait/firebase version 4.18 in PHP but when the program tries to process the .json or access credential it throws this error:

Fatal error: Uncaught GuzzleHttp \Exception\ConnectException : cURL error 35: Unknown SSL protocol error in connection to oauth2.googleapis.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html ) in C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php :185 Stack trace: #0 C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php (149): GuzzleHttp \Handler\CurlFactory ::createRejection(Object(GuzzleHttp \Handler\EasyHandle ), Array) #1 C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php (102): GuzzleHttp \Handler\CurlFactory ::finishError(Object(GuzzleHttp \Handler\CurlHandler ), Object(GuzzleHttp \Handler\EasyHandle ), Object(GuzzleHttp \Handler\CurlFactory )) #2 C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php (43): GuzzleHttp \Handler\CurlFactory ::finish(Object(GuzzleHttp \Handler\CurlHandler ), Object(GuzzleHttp \Handler\EasyHandle ), Object(GuzzleHttp \Handler\CurlFactory )) #3 C:\xampp\htdocs\bot -whatsapp \vendor\guzzle in C:\xampp\htdocs\bot -whatsapp \vendor\kreait\firebase -php \src\Firebase\Exception\QueryException.php on line 38

New error:

Fatal error: Uncaught GuzzleHttp \Exception\ClientException : Client error: POST https://oauth2.googleapis.com/token resulted in a 400 Bad Request response: { "error": "invalid_grant", "error_description": "Invalid JWT: Token must be a short-lived token (60 minutes) and in (truncated...) in C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\guzzle\src\Exception\RequestException.php :113 Stack trace: #0 C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\guzzle\src\Middleware.php (66): GuzzleHttp \Exception\RequestException ::create(Object(GuzzleHttp \Psr7\Request ), Object(GuzzleHttp \Psr7\Response )) #1 C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\promises\src\Promise.php (203): GuzzleHttp \Middleware ::GuzzleHttp{closure}(Object(GuzzleHttp \Psr7\Response ))

C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\promises\src\Promise.php (156):

GuzzleHttp \Promise\Promise ::callHandler(1, Object(GuzzleHttp \Psr7\Response ), Array) #3 C:\xampp\htdocs\bot -whatsapp \vendor\guzzlehttp\promises\src\TaskQueue.php (47): GuzzleHttp \Promise\Promise ::Guzz in C:\xampp\htdocs\bot -whatsapp \vendor\kreait\firebase -php \src\Firebase\Exception\QueryException.php on line 38

By executing this code in the method _construct() of my class:

private $serviceAccount;
private $firebase;
private $database;

function __construct(){
    $this->serviceAccount = ServiceAccount::fromJsonFile('bot-whatsapp-1d730-firebase-adminsdk-si780-59cb75b81e.json');

    $this->firebase = (new Factory)
        // The following line is optional if the project id in your credentials file
        // is identical to the subdomain of your Firebase project. If you need it,
        // make sure to replace the URL with the URL of your project.
    $this->database= $this->firebase->getDatabase();

And the research I did showed me that it could be a bug or problem related to my server time or since I am working using XAMPP (localhost), this should be my computer time (I think?). But in both sources that I got they solved their problem by modifying their time, one change the time of your equipment (convenient for me) and another the time of your server or host . Both sources were obtained from GitHub.

But I don't fully understand how they were able to determine how they should change the time, i.e., how they determined the time difference and then corrected it to work in conjunction with firebase.

I am a recent PHP programmer, I am more of a Java programmer, excuse my ignorance. Thank you and I look forward to your support.

0 votes

I don't think that is the problem. At least the error doesn't say anything about that, the reason it indicates is the following: cURL error 35: Unknown SSL protocol error in connection I don't think that has anything to do with the weather. Are you using cURL ? It would be nice if you could share how you send the request. cURL . The error may be due to a misspelled request, or because you have exceeded the query limits ( see here ) or things like that. It would be good for you to check for possible errors in the Google Project Console.

0 votes

My friend as far as I know I am using php lapi rest. I don't know if it uses any cURL requests on its own.

0 votes

This is the documentation link firebase-php.readthedocs.io/en/latest/ and I am using version 4.18


A. Cedano Points 48884

The documentation of the API you are using indicates that when there are errors in cURL If you have any problems with the certificate, they are due to a problem with the certificate:

If you receive an error cURL XX: ... Make sure you have a package of CA Root Certificates package on your system and that PHP uses it.

The following steps must be taken to carry out this review:

  1. Verify the status of the certificates by: var_dump(openssl_get_cert_locations());

  2. It will look something like this:

    array(8) {
        'default_cert_file' =>
        string(32) "/usr/local/etc/openssl/cert.pem"
        'default_cert_file_env' =>
        string(13) "SSL_CERT_FILE"
        'default_cert_dir' =>
        string(29) "/usr/local/etc/openssl/certs"
        'default_cert_dir_env' =>
        string(12) "SSL_CERT_DIR"
        'default_private_dir' =>
        string(31) "/usr/local/etc/openssl/private"
        'default_default_cert_area' =>
        string(23) "/usr/local/etc/openssl"
        'ini_cafile' =>
        string(0) ""
        'ini_capath' =>
        string(0) ""
  3. It is necessary to check if the file given in field default_cert_file really exists. Create a backup copy of the file, download the current CA package from https://curl.haxx.se/ca/cacert.pem and put it in the path that indicates default_cert_file .

Another alternative solution

If the problem persists, another possible solution is to configure curl.cainfo on file php.ini :

curl.cainfo = /absolute/path/to/cacert.pem

It is advisable to restart the server.

If the problem persists, review the different solutions proposed. in this thread .


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: