【问题标题】:Error trying to connect symfony 5 app with redis on heroku尝试将 symfony 5 应用程序与 heroku 上的 redis 连接时出错
【发布时间】:2020-06-04 07:42:20
【问题描述】:

我在尝试将 symfony 5 应用程序与 heroku 上的 redis 服务器连接时遇到问题。
- 我的 composer.json 和 composer.lock 设置了 ext-redis:"*"。

"require": {
        "php": "~7.4.0",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "ext-intl": "*",
        "ext-openssl": "*",
        "ext-redis": "*",
        ...
}
  • 我在 heroku 上有 3 个配置变量:

heroku redis 模块激活后创建的默认变量
REDIS_URL = redis://h:someHash@ec2.eu-west-1.compute.amazonaws.com:27269

自定义 var 以适应 php 类 Redis 构造函数
REDIS_HOST = redis://h:someHash@ec2.eu-west-1.compute.amazonaws.com
REDIS_PORT = 27269

我的部署因错误而停止:无法找到套接字传输“redis” - 您是否在配置 PHP 时忘记启用它?

部署完整日志:



-----> PHP app detected

-----> Bootstrapping...

-----> Installing platform packages...

       - php (7.4.6)

       - ext-intl (bundled with php)

       - ext-redis (5.2.2)

       - apache (2.4.43)

       - nginx (1.18.0)

-----> Installing dependencies...

       Composer version 1.10.6 2020-05-06 10:28:10

       Loading composer repositories with package information

       Installing dependencies from lock file

       Package operations: 108 installs, 0 updates, 0 removals

         - Installing ocramius/package-versions (1.8.0): Loading from cache

         - Installing symfony/flex (v1.6.3): Loading from cache

         - Installing symfony/polyfill-mbstring (v1.17.0): Loading from cache

         - Installing mtdowling/jmespath.php (2.5.0): Loading from cache

         - Installing ralouphie/getallheaders (3.0.3): Loading from cache

         - Installing psr/http-message (1.0.1): Loading from cache

         - Installing guzzlehttp/psr7 (1.6.1): Loading from cache

         - Installing guzzlehttp/promises (v1.3.1): Loading from cache

         - Installing symfony/polyfill-intl-idn (v1.17.0): Loading from cache

         - Installing guzzlehttp/guzzle (6.5.3): Loading from cache

         - Installing aws/aws-sdk-php (3.138.0): Loading from cache

         - Installing doctrine/cache (1.10.0): Loading from cache

         - Installing doctrine/collections (1.6.4): Loading from cache

         - Installing doctrine/inflector (1.4.1): Loading from cache

         - Installing doctrine/instantiator (1.3.0): Loading from cache

         - Installing doctrine/lexer (1.2.0): Loading from cache

         - Installing psr/container (1.0.0): Loading from cache

         - Installing symfony/service-contracts (v2.0.1): Loading from cache

         - Installing symfony/stopwatch (v5.0.8): Loading from cache

         - Installing symfony/polyfill-php73 (v1.17.0): Loading from cache

         - Installing symfony/console (v5.0.8): Loading from cache

         - Installing webimpress/safe-writer (2.0.1): Loading from cache

         - Installing laminas/laminas-zendframework-bridge (1.0.3): Loading from cache

         - Installing laminas/laminas-eventmanager (3.2.1): Loading from cache

         - Installing laminas/laminas-code (3.4.1): Loading from cache

         - Installing ocramius/proxy-manager (2.8.0): Loading from cache

         - Installing doctrine/event-manager (1.1.0): Loading from cache

         - Installing doctrine/dbal (2.10.2): Loading from cache

         - Installing doctrine/migrations (2.2.1): Loading from cache

         - Installing doctrine/annotations (1.10.2): Loading from cache

         - Installing doctrine/reflection (1.2.1): Loading from cache

         - Installing twig/twig (v3.0.3): Loading from cache

         - Installing symfony/translation-contracts (v2.0.1): Loading from cache

         - Installing symfony/validator (v5.0.8): Loading from cache

         - Installing symfony/twig-bridge (v5.0.8): Loading from cache

         - Installing symfony/mime (v5.0.8): Loading from cache

         - Installing symfony/http-foundation (v5.0.8): Loading from cache

         - Installing psr/event-dispatcher (1.0.0): Loading from cache

         - Installing symfony/event-dispatcher-contracts (v2.0.1): Loading from cache

         - Installing symfony/event-dispatcher (v5.0.8): Loading from cache

         - Installing symfony/var-dumper (v5.0.8): Loading from cache

         - Installing psr/log (1.1.3): Loading from cache

         - Installing symfony/error-handler (v5.0.8): Loading from cache

         - Installing symfony/http-kernel (v5.0.8): Loading from cache

         - Installing symfony/filesystem (v5.0.8): Loading from cache

         - Installing symfony/config (v5.0.8): Loading from cache

         - Installing symfony/twig-bundle (v5.0.8): Loading from cache

         - Installing symfony/translation (v5.0.8): Loading from cache

         - Installing symfony/security-core (v5.0.8): Loading from cache

         - Installing symfony/inflector (v5.0.8): Loading from cache

         - Installing symfony/property-access (v5.0.8): Loading from cache

         - Installing symfony/security-http (v5.0.8): Loading from cache

         - Installing symfony/security-guard (v5.0.8): Loading from cache

         - Installing symfony/security-csrf (v5.0.8): Loading from cache

         - Installing symfony/dependency-injection (v5.0.8): Loading from cache

         - Installing symfony/security-bundle (v5.0.8): Loading from cache

         - Installing symfony/routing (v5.0.8): Loading from cache

         - Installing symfony/finder (v5.0.8): Loading from cache

         - Installing symfony/var-exporter (v5.0.8): Loading from cache

         - Installing psr/cache (1.0.1): Loading from cache

         - Installing symfony/cache-contracts (v2.0.1): Loading from cache

         - Installing symfony/cache (v5.0.8): Loading from cache

         - Installing symfony/framework-bundle (v5.0.8): Loading from cache

         - Installing symfony/options-resolver (v5.0.8): Loading from cache

         - Installing symfony/intl (v5.0.8): Loading from cache

         - Installing symfony/polyfill-intl-icu (v1.17.0): Loading from cache

         - Installing symfony/form (v5.0.8): Loading from cache

         - Installing symfony/expression-language (v5.0.8): Loading from cache

         - Installing doctrine/persistence (1.3.7): Loading from cache

         - Installing symfony/doctrine-bridge (v5.0.8): Loading from cache

         - Installing symfony/asset (v5.0.8): Loading from cache

         - Installing pagerfanta/pagerfanta (v2.1.3): Loading from cache

         - Installing doctrine/common (2.12.0): Loading from cache

         - Installing doctrine/orm (v2.7.2): Loading from cache

         - Installing jdorn/sql-formatter (v1.2.17): Loading from cache

         - Installing doctrine/doctrine-bundle (2.0.8): Loading from cache

         - Installing easycorp/easyadmin-bundle (v2.3.8): Loading from cache

         - Installing behat/transliterator (v1.3.0): Loading from cache

         - Installing gedmo/doctrine-extensions (v2.4.41): Loading from cache

         - Installing symfony/process (v5.0.8): Loading from cache

         - Installing matleo/bank-statement-parser (dev-master 88ebc8e): Loading from cache

         - Installing phpdocumentor/reflection-common (2.1.0): Loading from cache

         - Installing phpdocumentor/type-resolver (1.1.0): Loading from cache

         - Installing sensio/framework-extra-bundle (v5.5.5): Loading from cache

         - Installing symfony/dotenv (v5.0.8): Loading from cache

         - Installing symfony/http-client-contracts (v2.0.1): Loading from cache

         - Installing symfony/http-client (v5.0.8): Loading from cache

         - Installing egulias/email-validator (2.1.17): Loading from cache

         - Installing symfony/mailer (v5.0.8): Loading from cache

         - Installing monolog/monolog (2.0.2): Loading from cache

         - Installing symfony/monolog-bridge (v5.0.8): Loading from cache

         - Installing symfony/monolog-bundle (v3.5.0): Loading from cache

         - Installing symfony/notifier (v5.0.8): Loading from cache

         - Installing doctrine/doctrine-migrations-bundle (2.1.2): Loading from cache

         - Installing symfony/orm-pack (v1.0.8): Loading from cache

         - Installing symfony/serializer (v5.0.8): Loading from cache

         - Installing symfony/property-info (v5.0.8): Loading from cache

         - Installing webmozart/assert (1.8.0): Loading from cache

         - Installing phpdocumentor/reflection-docblock (5.1.0): Loading from cache

         - Installing symfony/serializer-pack (v1.0.3): Loading from cache

         - Installing symfony/polyfill-intl-normalizer (v1.17.0): Loading from cache

         - Installing symfony/polyfill-intl-grapheme (v1.17.0): Loading from cache

         - Installing symfony/string (v5.0.8): Loading from cache

         - Installing twig/extra-bundle (v3.0.3): Loading from cache

         - Installing symfony/twig-pack (v1.0.0): Loading from cache

         - Installing psr/link (1.0.0): Loading from cache

         - Installing symfony/web-link (v5.0.8): Loading from cache

         - Installing symfony/yaml (v5.0.8): Loading from cache

       Generating optimized autoload files

       ocramius/package-versions: Generating version class...

       ocramius/package-versions: ...done generating version class

       62 packages you are using are looking for funding.

       Use the `composer fund` command to find out more!

       Executing script cache:clear [KO]

        [KO]

       Script cache:clear returned with error code 1

       !!  

       !!  In App_KernelProdContainer.php line 3884:

       !!                                                                                 

       !!    Unable to find the socket transport "redis" - did you forget to enable it w  

       !!    hen you configured PHP?                                                      

       !!                                                                                 

       !!  

       !!  

       Script @auto-scripts was called via post-install-cmd

 !     ERROR: Dependency installation failed!

 !     

 !     The 'composer install' process failed with an error. The cause

 !     may be the download or installation of packages, or a pre- or

 !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')

 !     in your 'composer.json'.

 !     

 !     Typical error cases are out-of-date or missing parts of code,

 !     timeouts when making external connections, or memory limits.

 !     

 !     Check the above error output closely to determine the cause of

 !     the problem, ensure the code you're pushing is functioning

 !     properly, and that all local changes are committed correctly.

 !     

 !     For more information on builds for PHP on Heroku, refer to

 !     https://devcenter.heroku.com/articles/php-support

 !     Push rejected, failed to compile PHP app.

 !     Push failed

我错过了扩展吗?

【问题讨论】:

  • 我认为问题出在使用 php-redis 扩展,当 Heroku 告诉使用 Predis 时。但是由于 Predis 不再维护,我怎样才能使它与 php-redis 扩展一起工作? heroku build 中似乎缺少 php-igbinary 模块

标签: heroku redis symfony5


【解决方案1】:

您只需要正确实例化 \Redis 对象。根据您提供的 Redis URL,它应该是这样的(phpredis 扩展的代码):

$redis = new \Redis();
$redis->connect('ec2.eu-west-1.compute.amazonaws.com', 27269);
$redis->auth('someHash');

这里的棘手部分是您不需要 Heroku 提供的 Redis URL 中的用户名“t”。

【讨论】:

  • 当我安装 Heroku Redis 插件时,它默认给我REDIS_URL 变量。有没有办法使用该字符串而不是将其分解为主机、端口和密码并将它们分别传递给connect() 方法?
  • 似乎 phpredis 扩展没有接受这种格式的连接字符串的接口:github.com/phpredis/phpredis#connect-open
猜你喜欢
  • 2020-07-21
  • 2021-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多