TransWikia.com

issue connecting Heroku PHP stack to Redis using Predis

Stack Overflow Asked by Rob Edlin on December 25, 2020

Hope someone can help with this as a new install of PHP and Heroku Redis

This is the error I’m getting:-
2020-12-14T19:46:37.368544+00:00 app[web.1]: [14-Dec-2020 19:46:37 UTC] PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
2020-12-14T19:46:37.368963+00:00 app[web.1]: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /app/vendor/predis/predis/src/Connection/StreamConnection.php on line 246
2020-12-14T19:46:37.369133+00:00 heroku[router]: at=info method=GET path="/v1/index.php" host=settingsapi.gtmforshopify.com request_id=b37a7e35-6813-4b57-98bc-96bcc9f0da20 fwd="82.69.152.94" dyno=web.1 connect=0ms service=53ms status=500 bytes=201 protocol=https
2020-12-14T19:46:37.369618+00:00 app[web.1]: [14-Dec-2020 19:46:37 UTC] PHP Fatal error: Uncaught PredisConnectionConnectionException: Error while switching to encrypted communication [rediss://ec2-23-21-210-25.compute-1.amazonaws.com:13579] in /app/vendor/predis/predis/src/Connection/AbstractConnection.php:155
2020-12-14T19:46:37.369716+00:00 app[web.1]: Stack trace:
2020-12-14T19:46:37.370064+00:00 app[web.1]: #0 /app/vendor/predis/predis/src/Connection/StreamConnection.php(247): PredisConnectionAbstractConnection->onConnectionError()
2020-12-14T19:46:37.370396+00:00 app[web.1]: #1 /app/vendor/predis/predis/src/Connection/StreamConnection.php(107): PredisConnectionStreamConnection->tlsStreamInitializer()
2020-12-14T19:46:37.370723+00:00 app[web.1]: #2 /app/vendor/predis/predis/src/Connection/AbstractConnection.php(81): PredisConnectionStreamConnection->createResource()
2020-12-14T19:46:37.376422+00:00 app[web.1]: #3 /app/vendor/predis/predis/src/Connection/StreamConnection.php(258): PredisConnectionAbstractConnection->connect()
2020-12-14T19:46:37.376880+00:00 app[web.1]: #4 /app/vendor/predis/predis/src/Connection/AbstractConnection.php(180): PredisConnectionStreamConnection->connect()
2020-12-14T19:46:37.377341+00:00 app[web.1]: #5 /app/vendor/predis/predis/src/Connection/StreamConnection.php(288): PredisConnectionAbstractConnection->getResource()
2020-12-14T19:46:37.377659+00:00 app[web.1]: #6 /app/vendor/predis/predis/src/Connect in /app/vendor/predis/predis/src/Connection/AbstractConnection.php on line 155

This is the code I’m using:-

PredisAutoloader::register();

if (getenv('REDIS_URL')) {
    $url = parse_url(getenv('REDIS_URL'));

    putenv('REDIS_HOST='.$url['host']);
    putenv('REDIS_PORT='.$url['port']);
    putenv('REDIS_PASSWORD='.$url['pass']);
    putenv('REDIS_SCHEME='.$url['scheme']);
}

$options = [];
$options['ssl']['allow_self_signed'] = TRUE;
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;

$redis = new PredisClient([
    'scheme'   => getenv('REDIS_SCHEME'),
    'host'   => getenv('REDIS_HOST'),
    'port'   => getenv('REDIS_PORT'),
    'password'   => getenv('REDIS_PASSWORD'),
    'database' => 0,
], $options);

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP