【问题标题】:Guzzle/Nexmo Issues After Upgrading to Laravel 8升级到 Laravel 8 后的 Guzzle/Nexmo 问题
【发布时间】:2021-08-26 21:53:32
【问题描述】:

我最近对这个网络应用程序进行了相当大的更新,并且在大多数情况下它顺利进行...直到应用程序尝试从登台/生产发送短信通知。

从 laravel 7.x 升级到 8.x 非常简单直接。同时我们也安装了 Laravel Horizo​​n。一切都按计划进行,并且在本地一切正常。

但是,当我们部署到暂存/生产时,排队的 SMS 通知会失败,并出现以下异常:

ReflectionException:/home/forge/dev.example.com/releases/20210609194554/vendor/laravel/framework/src/Illuminate/Container/Container.php:836 中不存在类 Http\Adapter\Guzzle6\Client /p>

查看堆栈跟踪,我们可以看到 Nexmo 是罪魁祸首:

#5 /home/forge/dev.example.com/releases/20210609194554/vendor/nexmo/laravel/src/NexmoServiceProvider.php(150): Illuminate\Foundation\Application->make()

但是在我们的 composer.json 文件中,我们需要 Guzzle 7 具有以下内容:

"guzzlehttp/guzzle": "^7.3",

在这一点上再次值得一提,我在本地发送 SMS 没有问题,本地和暂存环境的主要区别在于,我在本地使用 Laravel Valet,而 Staging 使用 Laravel Envoyer。

到目前为止我已经尝试过:

  • "guzzlehttp/guzzle": "^7.3" 更改为"guzzlehttp/guzzle": "^6.5|^7.3"
  • 在部署挂钩中手动运行 php artisan horizon:purgephp artisan horizon:terminate
  • 在 forge 上重新启动 laravel Horizo​​n 守护进程。
  • 正在尝试php artisan queue:restart
  • 运行composer dump-autoloadcomposer dump-autoload -o
  • 从 current/ 中删除 composer.lock 和 vendor/ 目录,然后运行 ​​composer install
  • 重启 PHP、Nginx,最终重启整个服务器 :(

还有更多...

非常感谢任何帮助

以下更新:

完整的composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.4.1",
        "arrilot/laravel-widgets": "^3.13",
        "barryvdh/laravel-snappy": "^0.4.6",
        "doctrine/dbal": "^2.10",
        "facade/ignition": "^2.3.6",
        "guzzlehttp/guzzle": "^7.3",
        "intervention/image": "^2.4",
        "laravel/framework": "^8.0",
        "laravel/helpers": "^1.3",
        "laravel/horizon": "^5.7",
        "laravel/nexmo-notification-channel": "^2.5.1",
        "laravel/passport": "^10.0",
        "laravel/slack-notification-channel": "^2.0",
        "laravel/telescope": "^4.0",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^3.0",
        "league/csv": "^8.2",
        "league/flysystem-aws-s3-v3": "~1.0",
        "maatwebsite/excel": "^3.1",
        "milon/barcode": "^8.0.1",
        "nexmo/laravel": "^2.4.1",
        "nunomaduro/collision": "^5.0",
        "predis/predis": "^1.1",
        "pusher/pusher-php-server": "^4.1.1",
        "webpatser/laravel-uuid": "^3.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "^9.0",
        "filp/whoops": "~2.0"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true
    }
}

此外,我的 nexmo 配置文件没有任何用于 http_client 的内容,也许这是我错过了某处的升级步骤。因此,对于nexmo 的http_client,我的.env 文件中没有任何内容。我也会开始研究这个。

nexmo.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | API Credentials
    |--------------------------------------------------------------------------
    |
    | If you're using API credentials, change these settings. Get your
    | credentials from https://dashboard.nexmo.com | 'Settings'.
    |
    */

    'api_key'    => function_exists('env') ? env('NEXMO_KEY', '') : '',
    'api_secret' => function_exists('env') ? env('NEXMO_SECRET', '') : '',

    /*
    |--------------------------------------------------------------------------
    | Signature Secret
    |--------------------------------------------------------------------------
    |
    | If you're using a signature secret, use this section. This can be used
    | without an `api_secret` for some APIs, as well as with an `api_secret`
    | for all APIs.
    |
    */

    'signature_secret' => function_exists('env') ? env('NEXMO_SIGNATURE_SECRET', '') : '',

    /*
    |--------------------------------------------------------------------------
    | Private Key
    |--------------------------------------------------------------------------
    |
    | Private keys are used to generate JWTs for authentication. Generation is
    | handled by the library. JWTs are required for newer APIs, such as voice
    | and media
    |
    */

    'private_key' => function_exists('env') ? env('NEXMO_PRIVATE_KEY', '') : '',
    'application_id' => function_exists('env') ? env('NEXMO_APPLICATION_ID', '') : '',

    /*
    |----------------------------------------------------------------------------
    | Phone Numbers
    |----------------------------------------------------------------------------
    |
    | Phone numbers to be used by the application.
    */

    'number'    =>  env('NEXMO_NUMBER'),
    'batch'     =>  env('NEXMO_BATCH'),

];

【问题讨论】:

    标签: php laravel nexmo envoyer.io laravel-envoyer


    【解决方案1】:

    我看到NexmoServiceProvider 正在尝试使用配置中定义的http_client,那么您能分享一下.envNEXMO_HTTP_CLIENT 的作用吗?我很确定你那里有问题,甚至没有定义。

    这就是在与该配置相关的config/nexmo.php 中定义的内容:

    'http_client' => function_exists('env') ? env('NEXMO_HTTP_CLIENT', '') : '',
    

    【讨论】:

    • 好电话,我完全错过了 nexmo 配置中的 http_client。在此过程中的一次升级中,我一定错过了与此有关的一些东西。我已经用 composer.json 和 config/nexmo.php 文件更新了我的问题。我将开始研究 http_client 配置设置。
    • @JustinM151 完全不用担心,这种事情有时会发生。查看我分享的代码 (NexmoServiceProvider),我很确定您必须编写 NEXMO_HTTP_CLIENT="\GuzzleHttp\Client" 并且应该这样做。它需要一个类,以便 Laravel 服务容器可以实现它,并且它需要实现 ClientInterface,以便我共享的对象正在实现它。测试一下,告诉我它是否有效
    • This(见here)需要一个ClientInterface,而GuzzleHttp\Client实现了它。
    • 我把它整理好了,你在正确的方向上轻推。非常感谢!
    • 很高兴我能帮上忙!我打算分享它正在尝试使用 Guzzle6 here,这是错误,但很高兴知道您现在已经解决了!
    猜你喜欢
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 2021-06-20
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多