guzzlehttp/guzzle 在将 php 更新为 php 8 后不起作用

guzzlehttp/guzzle dosn't work after update php to php 8

我在Laravel 8中使用了guzzlehttp/guzzle包。升级到 PHP 8 后,我得到:

Symfony\Component\ErrorHandler\Error\FatalError: Invalid opcode 117/2/0. in file ../vendor/defuse/php-encryption/src/Core.php on line 412

composer.json:

    "require": {
        "php": "^8.0",
        "doctrine/dbal": "^2.12.1",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^8.12",
        "laravel/passport": "^10.0",
        "laravel/tinker": "^2.5",
      "ext-json": "*"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },

php -v:

PHP 8.0.0RC3 (cli) (built: Oct 31 2020 17:06:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0RC3, Copyright (c), by Zend Technologies

UPD 1 If I call opcache_reset (); before $this->client = new \GuzzleHttp\Client; $response = $this->client->post(...), it works.

UPD 2 $ service php8.0-fpm reload - did not help.

UPD 3 Reboot server did not help.

我该如何解决这个问题?

问题不在于guzzlehttp/guzzle。问题是,on Ubuntu 20.10 PHP8 没有清除opcache.如果您在调用 new \GuzzleHttp\Client; 之前执行 opcache_reset();,那么一切正常。

正如@NikiC 在上面的评论中所说,它实际上是 PHP 中的一个错误。修复这里:https://github.com/php/php-src/commit/fdb05b92bfb62906771fd41f3fcdbc184d89e3fe

每次都重置 opcache 不是一个好主意,因为如果您要这样做,您也可能没有任何 opcache。