简体   繁体   English

升级到 Laravel 8 后的 Guzzle/Nexmo 问题

[英]Guzzle/Nexmo Issues After Upgrading to Laravel 8

I recently performed a rather large update to this web app, and for the most part it went off without a hitch... Until the app tries to send an SMS notification from staging/production.我最近对这个 web 应用程序进行了相当大的更新,并且在大多数情况下它顺利进行......直到应用程序尝试从登台/生产发送短信通知。

The upgrade from laravel 7.x to 8.x was quite simple and straightforward.从 laravel 7.x 升级到 8.x 非常简单明了。 At the same time we also installed Laravel Horizon.同时我们还安装了Laravel Horizon。 Everything went according to plan, and all works fine locally.一切都按计划进行,并且在本地一切正常。

When we deploy to staging/production however, queued SMS notifications fail with the following exception:但是,当我们部署到登台/生产时,排队的 SMS 通知会失败,并出现以下异常:

ReflectionException: Class Http\Adapter\Guzzle6\Client does not exist in /home/forge/dev.example.com/releases/20210609194554/vendor/laravel/framework/src/Illuminate/Container/Container.php:836 ReflectionException: Class Http\Adapter\Guzzle6\Client 不存在于 /home/forge/dev.example.com/releases/20210609194554/vendor/laravel/framework/src/Illuminate/Container/Container.ZE1BFD762321E409CEE4ZAC0B36E841963C

Looking in the stack trace we can see that Nexmo is the culprit:查看堆栈跟踪,我们可以看到 Nexmo 是罪魁祸首:

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

However in our composer.json file we are requiring Guzzle 7 with the following:然而,在我们的 composer.json 文件中,我们需要 Guzzle 7 的以下内容:

"guzzlehttp/guzzle": "^7.3",

It is worth mentioning again at this point, I have no issues sending SMS locally, the main difference between local and staging environments is that locally I use Laravel Valet and Staging uses Laravel Envoyer.在这一点上再次值得一提的是,我在本地发送短信没有问题,本地和暂存环境的主要区别在于,在本地我使用 Laravel Valet 而 Staging 使用 Laravel Envoyer。

What I've tried so far:到目前为止我已经尝试过:

  • Changing "guzzlehttp/guzzle": "^7.3" to "guzzlehttp/guzzle": "^6.5|^7.3""guzzlehttp/guzzle": "^7.3"更改为"guzzlehttp/guzzle": "^6.5|^7.3"
  • Running php artisan horizon:purge and php artisan horizon:terminate both manually and in a deployment hook.运行php artisan horizon:purgephp artisan horizon:terminate手动和部署挂钩。
  • Restarting the laravel horizon daemon on forge.在 forge 上重新启动 laravel 水平守护程序。
  • trying php artisan queue:restart尝试php artisan queue:restart
  • running composer dump-autoload and composer dump-autoload -o运行composer dump-autoloadcomposer dump-autoload -o
  • deleting composer.lock and the vendor/ directory from current/ then running composer install从 current/ 中删除 composer.lock 和 vendor/ 目录,然后运行composer install
  • Restarting PHP, Nginx, and eventually the entire server:(重新启动 PHP、Nginx,最终整个服务器:(

and more...和更多...

Any help is greatly appreciated任何帮助是极大的赞赏

UPDATE Below:更新如下:

Complete composer.json:完成作曲家.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
    }
}

Additionally my nexmo config file does not have anything for http_client, maybe it's an upgrade step I missed somewhere along the line.此外,我的 nexmo 配置文件没有任何用于 http_client 的内容,也许这是我错过的升级步骤。 As such, I have nothing in my.env file for nexmo's http_client.因此,对于nexmo 的http_client,我的.env 文件中没有任何内容。 I will begin looking into this as well.我也将开始研究这个。

nexmo.php 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'),

];

I see that the NexmoServiceProvider is trying to use the defined http_client in the config, so can you share what the .env has for NEXMO_HTTP_CLIENT ?我看到NexmoServiceProvider正在尝试使用配置中定义的http_client ,所以你能分享一下.envNEXMO_HTTP_CLIENT有什么吗? I am pretty sure you have something wrong there or even not defined.我很确定你那里有问题,甚至没有定义。

And this is what it is defined in the config/nexmo.php related to that config:这就是在与该配置相关的config/nexmo.php中定义的内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM