Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined function GuzzleHttp_idn_uri_convert() #2511

Closed
jkelley33tech opened this issue Dec 28, 2019 · 74 comments
Closed

Call to undefined function GuzzleHttp_idn_uri_convert() #2511

jkelley33tech opened this issue Dec 28, 2019 · 74 comments
Assignees

Comments

@jkelley33tech
Copy link

Hello - after the December 2019 updates, we are receiving the following error. Our client code calls into Guzzle at #2, so we don't call GuzzleHttp_idn_uri_convert() directly:

[28-Dec-2019 17:57:20 UTC] PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp_idn_uri_convert() in wp-content/plugins/q4vrplugin/vendor/guzzlehttp/guzzle/src/Client.php:220
Stack trace:
#0 guzzlehttp/guzzle/src/Client.php(155): GuzzleHttp\Client->buildUri(Object(GuzzleHttp\Psr7\Uri), Array)

#1 guzzlehttp/guzzle/src/Client.php(183): GuzzleHttp\Client->requestAsync('GET', 'units', Array)

#2 plugin/Models/ApiClient.php(97): GuzzleHttp\Client->request('GET', 'units', Array)

Please let me know what additional information I can provide to assist.

Thanks!

Jim

@gmponos
Copy link
Member

gmponos commented Dec 28, 2019

Please check this answer here: #2502 (comment)

execute a similar code to your system and let me know if the error persists..

@jkelley33tech
Copy link
Author

Hi @gmponos thanks for the quick reply. I don't have any sub applications that are calling guzzle, which is referenced in the #2502 Was there another action that I should take from that resolution?

Here is the log from our GitLab CI/CD build - showing only one guzzlehttp/guzzle installation:

image

Thanks again

Jim

@gmponos
Copy link
Member

gmponos commented Dec 28, 2019

Sorry maybe I was not clear. I wanted you to create a small reproducer like the one on my comment.

composer.json:

{
    "name": "gmponos/guzzle-issue-2502",
    "authors": [
        {
            "name": "Mponos George",
            "email": "gmponos@gmail.com"
        }
    ],
    "require": {
        "guzzlehttp/guzzle": "^6.5"
    }
}
<?php

require_once 'vendor/autoload.php';

$client = new GuzzleHttp\Client();
$response = $client->request('get', 'www.google.com', [
    \GuzzleHttp\RequestOptions::IDN_CONVERSION => true,
]);

var_dump($response->getStatusCode()); // outputs 200

I have also added a var_dump inside _idn_uri_convert and the code above reached there..

Execute the reproducer at your serer and let me know of the result...

Also the info you provide at your first comment are a littke bit scrambled and they do not help...

@gmponos gmponos self-assigned this Dec 28, 2019
@sagikazarmark
Copy link
Member

Based on this line, this is a WordPress plugin:

wp-content/plugins/q4vrplugin/vendor/guzzlehttp/guzzle/src/Client.php:220

Chances are you have other plugins autoloading an earlier version of Guzzle (similar to the subapplication case).

Please check if any other plugins install wordpress and if so, they install the latest version.

@MattheusRossopIII
Copy link

MattheusRossopIII commented Jan 2, 2020

I'm also getting this issue. I use the https://github.com/googleapis/google-api-php-client project to verify in-app purchases on my backend.

My composer set up is as follows:

{ "require": { "google/apiclient": "~2.0" } }

It would seem that the google-api-php-client uses guzzle and thus when I execute one of the API calls, it uses the wrong version of guzzle.

Any suggestions on what I can do? Any help appreciated.

@gmponos
Copy link
Member

gmponos commented Jan 2, 2020

@MattheusRossopIII in order to find the bug I will need a reproducer.. similar as my example above.. with more details about the platform (curl and php version.. is intl installed?)

The function exists in 6.5.2 https://github.com/guzzle/guzzle/blob/6.5.2/src/functions.php#L358 and this issue (#2502) and the fact that it is resolved confirms that the function is there... :/

@MattheusRossopIII
Copy link

MattheusRossopIII commented Jan 2, 2020

@gmponos Some more details:
stack trace: PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\\_idn_uri_convert() in /var/app/current/vendor/guzzlehttp/guzzle/src/Client.php:220\nStack trace:\n#0 /var/app/current/vendor/guzzlehttp/guzzle/src/Client.php(113): GuzzleHttp\\Client->buildUri(Object(GuzzleHttp\\Psr7\\Uri), Array)\n#1 /var/app/current/vendor/guzzlehttp/guzzle/src/Client.php(130): GuzzleHttp\\Client->sendAsync(Object(GuzzleHttp\\Psr7\\Request), Array)\n#2 /var/app/current/vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php(34): GuzzleHttp\\Client->send(Object(GuzzleHttp\\Psr7\\Request), Array)\n#3 /var/app/current/vendor/google/apiclient/src/Google/Http/REST.php(74): Google\\Auth\\HttpHandler\\Guzzle6HttpHandler->__invoke(Object(GuzzleHttp\\Psr7\\Request))\n#4 /var/app/current/vendor/google/apiclient/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\\Client), Object(GuzzleHttp\\Psr7\\Request), 'Google_Service_...')\n#5 /var/app/current/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run()\n#6 /var/app/cur in /var/app/current/vendor/guzzlehttp/guzzle/src/Client.php on line 220

Code that now fails:
$client = new Google_Client(); $client->useApplicationDefaultCredentials(); $client->addScope('https://www.googleapis.com/auth/androidpublisher'); $service = new Google_Service_AndroidPublisher($client); $purchase = $service->purchases_products->get($applicationIdentifier, $productID, $purchaseToken);

PHP info:
PHP 7.2.18 (cli) (built: May 24 2019 21:14:49) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies

Curl info:
curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.0.2k zlib/1.2.8 libidn2/0.16 libpsl/0.6.2 (+libicu/50.1.2) libssh2/1.4.2 nghttp2/1.21.1 Release-Date: 2018-09-05 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy PSL

@gmponos
Copy link
Member

gmponos commented Jan 2, 2020

  • What is the Guzzle version you are using? can you do a composer show | grep guzzle?
  • In your files does the function _idn_uri_convert exists inside the function.php
  • Can you do a check and inside your vendor check /vendor/guzzlehttp/guzzle/src/Client.php:220 change the line to GuzzleHttp\_idn_uri_convert.. if by any chance this works ( i doubt this is the issue change it back and test again)

@MattheusRossopIII
Copy link

  • I cannot run a composer command as I'm using an AWS instance. When Elastic Beanstalk creates my EC2 instances, it uses the composer.json document that I posted earlier in this thread.

The /var/www/html/vendor/guzzlehttp/guzzle/composer.json is as follows (not sure if helpful):
{ "name": "guzzlehttp/guzzle", "type": "library", "description": "Guzzle is a PHP HTTP client library", "keywords": [ "framework", "http", "rest", "web service", "curl", "client", "HTTP client" ], "homepage": "http://guzzlephp.org/", "license": "MIT", "authors": [ { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" } ], "require": { "php": ">=5.5", "ext-json": "*", "guzzlehttp/promises": "^1.0", "guzzlehttp/psr7": "^1.6.1" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "psr/log": "^1.1" }, "suggest": { "psr/log": "Required for using the Log middleware", "ext-intl": "Required for Internationalized Domain Name (IDN) support" }, "config": { "sort-packages": true }, "extra": { "branch-alias": { "dev-master": "6.5-dev" } }, "autoload": { "psr-4": { "GuzzleHttp\\": "src/" }, "files": [ "src/functions_include.php" ] }, "autoload-dev": { "psr-4": { "GuzzleHttp\\Tests\\": "tests/" } } }

  • /var/app/current/vendor/guzzlehttp/guzzle/src/Client.php includes the following function (see line 220)
    This Client.php script doesn't have a _idn_uri_convert function. (hence why it's crashing)

/** 205 * @param string|null $uri 206 * 207 * @return UriInterface 208 */ 209 private function buildUri($uri, array $config) 210 { 211 // for BC we accept null which would otherwise fail in uri_for 212 $uri = Psr7\uri_for($uri === null ? '' : $uri); 213 214 if (isset($config['base_uri'])) { 215 $uri = Psr7\UriResolver::resolve(Psr7\uri_for($config['base_uri']), $uri); 216 } 217 218 if (isset($config['idn_conversion']) && ($config['idn_conversion'] !== false)) { 219 $idnOptions = ($config['idn_conversion'] === true) ? IDNA_DEFAULT : $config['idn_conversion']; 220 $uri = _idn_uri_convert($uri, $idnOptions); 221 } 222 223 return $uri->getScheme() === '' && $uri->getHost() !== '' ? $uri->withScheme('http') : $uri; 224 }

/var/app/current/vendor/guzzlehttp/guzzle/src/functions.php includes this in the script:
`
/**

  • @param int $options

  • @return UriInterface

  • @internal
    */
    function _idn_uri_convert(UriInterface $uri, $options = 0)
    {
    if ($uri->getHost()) {
    $idnaVariant = defined('INTL_IDNA_VARIANT_UTS46') ? INTL_IDNA_VARIANT_UTS46 : 0;
    $asciiHost = $idnaVariant === 0
    ? idn_to_ascii($uri->getHost(), $options)
    : idn_to_ascii($uri->getHost(), $options, $idnaVariant, $info);
    if ($asciiHost === false) {
    $errorBitSet = isset($info['errors']) ? $info['errors'] : 0;

         $errorConstants = array_filter(array_keys(get_defined_constants()), function ($name) {
             return substr($name, 0, 11) === 'IDNA_ERROR_';
         });
    
         $errors = [];
         foreach ($errorConstants as $errorConstant) {
             if ($errorBitSet & constant($errorConstant)) {
                 $errors[] = $errorConstant;
             }
         }
    
         $errorMessage = 'IDN conversion failed';
         if ($errors) {
             $errorMessage .= ' (errors: ' . implode(', ', $errors) . ')';
         }
    
         throw new InvalidArgumentException($errorMessage);
     } else {
         if ($uri->getHost() !== $asciiHost) {
             // Replace URI only if the ASCII version is different
             $uri = $uri->withHost($asciiHost);
         }
     }
    

    }

    return $uri;
    }
    `

The Client.php line 220 needs to be changed to use the functions.php _idn_uri_convert method I suggest? I can't do this obviously as each time AWS EB creates new EC2 instances and the problem will persist!

@luisadame
Copy link

@gmponos This happens to me on a laravel test case. If i run your code on a simple php file it works fine. However this happens on a fresh laravel project.

ExampleTest.php

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use GuzzleHttp\Client;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $client = new Client();
        $response = $client->request('get', 'www.google.com');
        $this->assertEquals(200, $response->getStatusCode());
    }
}

Result from phpunit

PHPUnit 8.5.1 by Sebastian Bergmann and contributors.
PHP Notice:  Undefined index: warnings in /home/luis/Documents/Sites/testguzzle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 334
PHP Warning:  Invalid argument supplied for foreach() in /home/luis/Documents/Sites/testguzzle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 334

.E                                                                  2 / 2 (100%)

Time: 100 ms, Memory: 16.00 MB

There was 1 error:

1) Tests\Feature\ExampleTest::testBasicTest
Error: Call to undefined function GuzzleHttp\_idn_uri_convert()

/home/luis/Documents/Sites/testguzzle/vendor/guzzlehttp/guzzle/src/Client.php:220
/home/luis/Documents/Sites/testguzzle/vendor/guzzlehttp/guzzle/src/Client.php:155
/home/luis/Documents/Sites/testguzzle/vendor/guzzlehttp/guzzle/src/Client.php:183
/home/luis/Documents/Sites/testguzzle/tests/Feature/ExampleTest.php:19
/home/luis/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:200
/home/luis/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:155

ERRORS!
Tests: 2, Assertions: 1, Errors: 1.

composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.5",
        "laravel/framework": "^6.2",
        "laravel/tinker": "^2.0"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

@GrahamCampbell
Copy link
Member

Can you paste your composer.lock file too please?

@luisadame
Copy link

luisadame commented Jan 5, 2020

@GrahamCampbell of course.

Edit: there was a composer.lock content pasted here, but I came to a solution on #2511 (comment)

@luisadame
Copy link

@GrahamCampbell @gmponos Ok guys, I looked into my global composer packages, and I had Guzzle on version 6.3.3, I updated global packages which also upgraded PHPUnit and the test passes now. Do you have any idea why a global package can interfere with a project's dependency, shouldn't it execute the local project dependency files? Thanks.

@GrahamCampbell
Copy link
Member

Was the global dependency the laravel installer?

@gmponos
Copy link
Member

gmponos commented Jan 5, 2020

I believe that the fact that 2 out of 4 related problems reported is hinting that the issue most probably is not in guzzle..

Never the less there is the benefit of doubt. Out of the info that we have for the reported issue we can not provide currently a solution since AFAIK the code is working.

PS. @mrluissan can you just replace with composer show or just remove it since you found the solution... it makes current issue huge

@luisadame
Copy link

@GrahamCampbell Yes, I do have the laravel installer as a global dependency, and guzzle too. I don't know if installing the laravel installer globally it also installs Guzzle separately. I'm gonna paste my current composer global show output:

composer/semver                        1.5.0    Semver library that offers utilities, version constraint parsing and validation.
composer/xdebug-handler                1.4.0    Restarts a process without Xdebug.
cpriego/valet-linux                    v2.2.10  A more enjoyable local development experience for Linux.
deployer/deployer                      v6.7.3   Deployment Tool
deployer/phar-update                   v2.2.0   Integrates Phar Update to Symfony Console.
doctrine/annotations                   v1.8.0   Docblock Annotations Parser
doctrine/instantiator                  1.3.0    A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                         1.2.0    PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
escapestudios/symfony2-coding-standard 3.10.0   CodeSniffer ruleset for the Symfony 2+ coding standard
friendsofphp/php-cs-fixer              v2.16.1  A tool to automatically fix PHP code style
guzzlehttp/guzzle                      6.5.2    Guzzle is a PHP HTTP client library
guzzlehttp/promises                    v1.3.1   Guzzle promises library
guzzlehttp/psr7                        1.6.1    PSR-7 message implementation that also provides common utility methods
illuminate/container                   v6.8.0   The Illuminate Container package.
illuminate/contracts                   v6.8.0   The Illuminate Contracts package.
jean85/pretty-package-versions         1.2      A wrapper for ocramius/package-versions to get pretty versions strings
laravel/installer                      v2.3.0   Laravel application installer.
mnapoli/silly                          1.7.2    Silly CLI micro-framework based on Symfony Console
myclabs/deep-copy                      1.9.4    Create deep copies (clones) of your objects
nategood/httpful                       0.3.0    A Readable, Chainable, REST friendly, PHP HTTP Client
nette/bootstrap                        v3.0.1   🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.
nette/di                               v3.0.2   💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.
nette/finder                           v2.5.2   🔍 Nette Finder: find files and directories with an intuitive API.
nette/neon                             v3.1.0   🍸 Nette NEON: encodes and decodes NEON file format.
nette/php-generator                    v3.3.2   🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.4 features.
nette/robot-loader                     v3.2.1   🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.
nette/schema                           v1.0.1   📐 Nette Schema: validating data structures against a given Schema.
nette/utils                            v3.1.0   🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password gene...
nikic/php-parser                       v4.3.0   A PHP parser written in PHP
ocramius/package-versions              1.5.1    Composer plugin that provides efficient querying for installed package versions (no runtime IO)
paragonie/random_compat                v9.99.99 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                       1.0.3    Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                        2.0.1    Library for handling version information and constraints
php-cs-fixer/diff                      v1.3.0   sebastian/diff v2 backport support for PHP5.6
php-di/invoker                         2.0.0    Generic and extensible callable invoker
phpdocumentor/reflection-common        2.0.0    Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock      4.3.4    With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver            1.0.1    A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/prophecy                       1.10.1   Highly opinionated mocking framework for PHP 5.3+
phpstan/phpdoc-parser                  0.3.5    PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                        0.10.8   PHPStan - PHP Static Analysis Tool
phpunit/php-code-coverage              6.1.4    Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator              2.0.2    FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template              1.2.1    Simple template engine.
phpunit/php-timer                      2.1.2    Utility class for timing
phpunit/php-token-stream               3.1.1    Wrapper around PHP's tokenizer extension.
phpunit/phpunit                        7.5.18   The PHP Unit Testing framework.
pimple/pimple                          v3.2.3   Pimple, a simple Dependency Injection Container
psr/container                          1.0.0    Common Container Interface (PHP FIG PSR-11)
psr/http-message                       1.0.1    Common interface for HTTP messages
psr/log                                1.1.2    Common interface for logging libraries
psr/simple-cache                       1.0.1    Common interfaces for simple caching
ralouphie/getallheaders                3.0.3    A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup     1.0.1    Looks up which function or method a line of code belongs to
sebastian/comparator                   3.0.2    Provides the functionality to compare PHP values for equality
sebastian/diff                         3.0.2    Diff implementation
sebastian/environment                  4.2.3    Provides functionality to handle HHVM/PHP environments
sebastian/exporter                     3.1.2    Provides the functionality to export PHP variables for visualization
sebastian/global-state                 2.0.0    Snapshotting of global state
sebastian/object-enumerator            3.0.3    Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector             1.1.1    Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context            3.0.0    Provides functionality to recursively process PHP variables
sebastian/resource-operations          2.0.1    Provides a list of PHP built-in functions that operate on resources
sebastian/version                      2.0.1    Library that helps with managing the version number of Git-hosted PHP projects
squizlabs/php_codesniffer              3.5.3    PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
symfony/console                        v4.4.2   Symfony Console Component
symfony/event-dispatcher               v4.4.2   Symfony EventDispatcher Component
symfony/event-dispatcher-contracts     v1.1.7   Generic abstractions related to dispatching event
symfony/filesystem                     v4.4.2   Symfony Filesystem Component
symfony/finder                         v4.4.2   Symfony Finder Component
symfony/options-resolver               v5.0.2   Symfony OptionsResolver Component
symfony/polyfill-ctype                 v1.13.1  Symfony polyfill for ctype functions
symfony/polyfill-mbstring              v1.13.1  Symfony polyfill for the Mbstring extension
symfony/polyfill-php70                 v1.13.1  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72                 v1.13.1  Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73                 v1.13.1  Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/process                        v4.4.2   Symfony Process Component
symfony/service-contracts              v2.0.1   Generic abstractions related to writing services
symfony/stopwatch                      v5.0.2   Symfony Stopwatch Component
symfony/var-dumper                     v5.0.2   Symfony mechanism for exploring and dumping PHP variables
symfony/yaml                           v5.0.2   Symfony Yaml Component
theseer/tokenizer                      1.1.3    A small library for converting tokenized PHP source code into XML and potentially other formats
tightenco/collect                      v6.9.0   Collect - Illuminate Collections as a separate package.
webmozart/assert                       1.6.0    Assertions to validate method input/output with nice error messages.

@gmponos I don't understand what you are actually telling me to try, sorry. I don't have a solid knowledge of how Composer works. If you can elaborate it more I'll try gladly.

@gmponos
Copy link
Member

gmponos commented Jan 5, 2020

I meant on the comment above replace the contents with composer show or delete the comment. it is not needed all the lock file since you've found the solution.

@GrahamCampbell
Copy link
Member

I wonder if the laravel installer should try a phar distribution strategy without dependencies, like phpstan 0.12 does, to mitigate these types of problems. // cc @taylorotwell @driesvints

@GrahamCampbell
Copy link
Member

That is, you install the package through composer still, but what that actually does is download the phar using composer.

@sagikazarmark
Copy link
Member

Do you have any idea why a global package can interfere with a project's dependency, shouldn't it execute the local project dependency files?

The problem is the always autoloaded functions. There is a condition in the beginning of the file to check if one of the functions already exist. If it does, it won't load them again.

This was a "fix" for global package usage in the first place. I'm guessing the global package is loaded first.

Not sure what would be the correct fix here. We could move the functions to a util class as static functions, that would eliminate the need to always load the functions file. I guess the autoloader will check package dependencies first.

Although I find it odd that a different version of the same package is autoloaded in the first place.

@MattheusRossopIII
Copy link

Can anybody suggest a solution for developers like myself who are experiencing the issue using the google-api-php-client using AWS? Everything was working fine until a few weeks ago and now the Guzzle dependency is failing.

So our set up is using composer to load the latest google-api-php-client library. This library in turn uses Guzzle, but it's failing (as documented above).

Any suggestions will be appreciated and I can test them to see if they will work for us.

@mfn
Copy link

mfn commented Jan 7, 2020

I'm also a user of google/apiclient but haven't had a bad experience yet.

Note that google/apiclient has this guzzle dependency:
"guzzlehttp/guzzle": "~5.3.1||~6.0",

So it works with either 5 or 6.

However in my project I a) don't have global dependency and b) I've an explicit root dependency (for other parts) on guzzlehttp/guzzle 6.

@ChrisThompsonTLDR
Copy link

We are experiencing this with 6.5.2 but not with 6.5.0. Using a stock Laravel install 6.10.1.

What information can I provide to help debug this?

@jerrebm
Copy link

jerrebm commented Jan 10, 2020

We are experiencing this with 6.5.2 but not with 6.5.0. Using a stock Laravel install 6.10.1.

What information can I provide to help debug this?

Same here! Downgraded from 6.5.2 to 6.5.0, that resolved the issue.

@sagikazarmark
Copy link
Member

@MattheusRossopIII @ChrisThompsonTLDR @egyptik can you please check/confirm that you don't have Guzzle installed globally?

It might get installed with a tool that you install globally in your workspace

eg. cat ~/.composer/composer.json | grep guzzle

@jerrebm
Copy link

jerrebm commented Jan 10, 2020

@sagikazarmark Just checked - I don't. But I am also using google/apiclient like @MattheusRossopIII and @mfn

@sagikazarmark
Copy link
Member

In this case, can you give me a composer.json and a main.php snippet that I can use to reproduce this issue?

@ChrisThompsonTLDR
Copy link

ChrisThompsonTLDR commented Jan 10, 2020

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^6.2",
        "laravel/tinker": "^1.0",

        "guzzlehttp/guzzle": "6.5.0"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": false
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

I do not have Guzzle installed globally.

My application doesn't have a main.php.

@sagikazarmark
Copy link
Member

I meant a simple PHP script that executing from the CLI reproduces the issue.

@edi
Copy link

edi commented Feb 13, 2020

@GrahamCampbell Beg your pardon.. but, given I use google/cloud-firestore, which isn’t directly requiring guzzle (does it through sub-packages like google-auth and cloud-core), how do I force your patch into it?

Do I simply append it in the composer file? I’m on mobile now, that’s why I asked rather than try it out. Meanwhile, I’ve worked around it by adding the exists check to each function, given it wont upgrade unless I want it to.

Regards!

@ChrisThompsonTLDR
Copy link

@edi, you would put this in your application's composer.json file

    "require": {
        "guzzlehttp/guzzle": "dev-6.5-functions as 6.5.3"
    },
    "repositories": [
        {"type": "vcs", "url": "git@github.com:GrahamCampbell/guzzle.git"}
    ]

@theqdev
Copy link

theqdev commented Mar 29, 2020

I had a similar case on a laravel 5.8 where I was executing some queue jobs via a supervisor service.

Looks like the service worker was loading some old autoload file, so only supervisorctl restart all saved my day.

@bshaffer
Copy link

bshaffer commented Apr 14, 2020

Sorry, but when will this fix be pushed? It's been months and most of our libraries are failing with this error because they're trying to use v6.5.2 of Guzzle. These are regular PHP fatal errors on the most recently tagged version.

@giovannipds
Copy link

@bshaffer You can always use older versions until it's fixed... I it's not what you want, but, it's something... 😄

@bshaffer
Copy link

@giovannipds This is a good idea, although we will want to continue with semantic versioning once the bug gets fixed. We can try excluding the errant version in our core library like this:

{ 
    "require": {
        "guzzlehttp/guzzle": "~5.3.1|~6.0, !=6.5.2" 
    }
}

I am curious if there is justification for why the fix has taken so long (pinging @gmponos)

@GrahamCampbell
Copy link
Member

#2548 together with #2550 will fix all reported intl issues.

@Nyholm
Copy link
Member

Nyholm commented Apr 15, 2020

Thank you @GrahamCampbell.

I've merged your two fixes. I will start to prepare a release for 6.5.3

@Nyholm
Copy link
Member

Nyholm commented Apr 15, 2020

Please install 6.5.x-dev and try it out. That will make me more comfortable releasing the new version.

{ 
    "require": {
        "guzzlehttp/guzzle": "6.5.x-dev" 
    }
}

@flowl
Copy link

flowl commented Apr 15, 2020

@Nyholm It works for me, no more errors. I'm using quite a lot of stuff applied to the client (Middleware) and nothing fails.

@jagermesh
Copy link

jagermesh commented Apr 19, 2020

Upgraded to 6.5.3 via composer update and issue still there

@Nyholm
Copy link
Member

Nyholm commented Apr 19, 2020

@jagermesh Could you open a new issue where you show a stack trace?

@jagermesh
Copy link

@jagermesh Could you open a new issue where you show a stack trace?

sorry, it was in sub-project which has own composer.json, seems fine after both were upgraded

@bkdotcom
Copy link

bkdotcom commented Dec 1, 2020

For me, this issue occurred when requiring a second project's autoloader that had a different version of guzzle

require __DIR__ . '/vendor/autoload.php';
require '/some/other/vendor/autoload.php';  // trouble introduced here

@Nyholm
Copy link
Member

Nyholm commented Dec 1, 2020

Yes @bkdotcom, you are very correct.

If you have more than one installation of guzzle, and they are of different versions. Then yes, you will have issues with your autoloader. I mean.. you are loading two classes with the exact same FQCN.

Im locking this issue since all the answers is already written. If someone still have issues, feel free to open a new issue.

@guzzle guzzle locked as resolved and limited conversation to collaborators Dec 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests