Michael Dowling is working on a version 4 of Guzzle, which he has informed me should be out "in about a month" (which would be April sometime). Version 3 will still be supported, but he and I both agree that we should plan to upgrade once it's out.

I am marking this postponed for the time being until it's out, but then we can upgrade.

The biggest changes I am aware of that should affect us are:

* It uses its own mini event system rather than the Symfony event dispatcher. (Doesn't hurt us, but we'll have a listener or two to adjust.)
* Curl is no longer a hard requirement, cf #1991298: Fatal error when installing Drupal on servers that don't have the cURL extension
* The mocking plugin will be pulled into the main package, which will deprecate #2209021: Guzzle mock plugin is not included

Nothing really dramatic, so the upgrade should be easy since we're not at RC yet. It should future-proof us better, though.

References:

http://docs.guzzlephp.org/en/guzzle4/
http://docs.guzzlephp.org/en/guzzle4/clients.html#creating-a-client
https://twitter.com/mtdowling/status/440901351657054208 (and following)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

Title: Upgrade to guzzle 4 » Upgrade to Guzzle 4
catch’s picture

Priority: Major » Critical

Marked #1991298: Fatal error when installing Drupal on servers that don't have the cURL extension as duplicate.

Bumping to critical, the other issue is only major but combination of small API changes and fixing that major bug tips it over I think.

Berdir’s picture

* Curl is no longer a hard requirement,

What does this mean exactly? That it *would* be possible to have an implementation that doesn't use curl or that it will actually provide one out of the box?

tstoeckler’s picture

From the docs there:

Note
Guzzle no longer requires cURL in order to send HTTP requests. Guzzle will use the PHP stream wrapper to send HTTP requests if cURL is not installed. Alternatively, you can provide your own HTTP adapter used to send requests.

mtdowling’s picture

Guzzle 4.0.0 stable has been released! See: http://mtdowling.com/blog/2014/03/29/guzzle4/

tstoeckler’s picture

Status: Postponed » Active
damiankloip’s picture

Assigned: Unassigned » damiankloip

Patch shortly

damiankloip’s picture

Status: Active » Needs review
FileSize
1.46 MB

Initial patch.

I think we might have an issue with this, from core.service.yml:

- [addSubscriber, ['@http_client_simpletest_subscriber']]

There are no longer proxy methods like before to the event dispatcher (now emitter). So you cannot add subscribers directly on the client. You now have to use something like:

$client->getEmitter()->attach($sub);

afaik, we can't do this with calls now. But also not in a service provider etc..

damiankloip’s picture

Assigned: damiankloip » Unassigned

Status: Needs review » Needs work

The last submitted patch, 8: 2210637.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.46 MB
2.17 KB

One solution would be to extend the Guzzle Client with our own we can then set our default header option in there instead? Would be good to get your thoughts on the issue above and this solution @mtdowling :)

Status: Needs review » Needs work

The last submitted patch, 11: 2210637-11.patch, failed testing.

mtdowling’s picture

What was the subscriber doing? It sounds like it was adding a header. If that is the case, then I think you can do that in you core.service.yml (here's the PHP code):

$client->setDefaultOption('headers/foo', 'bar');

Berdir’s picture

Yes, but that header is dynamic and based on the function drupal_generate_test_ua(), not sure we can move that to a harcoded method call, maybe if we do it in a service provider?

damiankloip’s picture

This is why I was suggesting moving this logic into an extended class instead. Removing the subscriber. It is unfortunately dynamic so cannot live in a yaml service definition :/

Because right now we can't do a direct port of the logic in guzzle 4.

damiankloip’s picture

FileSize
1.46 MB
2.54 KB

Some more fixes. Currently it will still be broken, I am seeing this error in the watchdog log:

WD cron: InvalidArgumentException: No method is configured to handle the Accept config key in GuzzleHttp\Message\MessageFactory->applyOptions() (line 164 of                                   [error]
/Users/damian.lee/Sites/D8/core/vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php).
damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.47 MB
6.48 KB

Some more changes, sorry for the noise! Realised I didn't change most of the use statements. I guess that doesn't help :)

Status: Needs review » Needs work

The last submitted patch, 17: 2210637-17.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.48 MB
9.96 KB

Oops, missed some stuff from my local branch in that patch! No wonder there was still some stuff missing... Patches first thing in the morning --

Status: Needs review » Needs work

The last submitted patch, 19: 2210637-19.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.48 MB
3.51 KB

or could we just move everything to our own client, and just merge them as defaults?

Status: Needs review » Needs work

The last submitted patch, 21: 2210637-21.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.48 MB
3.88 KB

Oops, we need to keep the simpletest header modification in the subscriber so it fires for each request, not just when the service is first instantiated.

Status: Needs review » Needs work

The last submitted patch, 23: 2210637-23.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.48 MB
6.41 KB

Fixed the rest of the ->send() calls when responses are already returned.

Status: Needs review » Needs work

The last submitted patch, 25: 2210637-25.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.48 MB
6.27 KB

This should fix the other failures/exceptions. Let's see if simpletest will return us some results now. Might still get that weird FATAL error...

Status: Needs review » Needs work

The last submitted patch, 27: 2210637-27.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.5 MB
886 bytes
damiankloip’s picture

FileSize
1.48 MB
1.89 KB

Fixed options.

I think the certificate_authority option is now just 'verify' in Guzzle 4. The default is the bundled Guzzle 4 pem file. So if we override this to TRUE, it will use the system file.

neclimdul’s picture

I stepped through the code with a debugger since I couldn't make heads or tails of how they where delegating things and coming up with configuration/options. I can confirm 'verify' does as damian said. Can't see anything wrong and some manual testing of aggregator seemed to work well and looking at the changes the look to mostly just contain the API changes.

The only question I have is if it might be possible to avoid including the simpletest listener at all if not needed or have simpletest register it. I didn't look into how feasible that is.

damiankloip’s picture

Thanks for confirming. Seems we both arrived at the same conclusion which is good :)

I advocated removing this subscriber and only adding it for tests in #2168809: Do not add the Guzzle HTTP client request subscriber outside of test environment. It got a bit of resistance so I would like to just try and get this in, and tackle that there if we can? I would definitely prefer it was only registered for tests though.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Awesome. Guzzle++

I reviewed all changes to core and I wasn't able to spot any issues. Looks great to me.

Note that this patch only performs the major upgrade for Guzzle — we'll look into further improvement options (e.g. no longer relying on cURL) in separate issues.

damiankloip’s picture

Opened #2237681: Revise Guzzle client configuration and event registration as a follow up to this. There we can discuss how to move forward with event registration etc...

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

  • Commit e84971c on 8.x by webchick:
    Issue #2210637 by damiankloip | Crell: Upgrade to Guzzle 4.
    
tim.plunkett’s picture

Getting this once in a while now. Seems like Guzzle is the only thing using PSR-4, so posting here.

Fatal error: Call to undefined method Composer\Autoload\ClassLoader::setPsr4() in /Users/timplunkett/www/d8/core/vendor/composer/autoload_real.php on line 40

Call Stack:
    0.0028     267832   1. {main}() /Users/timplunkett/.bin/drush_lib/drush.php:0
    0.0259    2577880   2. drush_main() /Users/timplunkett/.bin/drush_lib/drush.php:16
    0.1652    7763520   3. _drush_bootstrap_and_dispatch() /Users/timplunkett/.bin/drush_lib/drush.php:68
    0.2649    7769128   4. drush_bootstrap_to_phase() /Users/timplunkett/.bin/drush_lib/drush.php:94
    0.2662    7771752   5. drush_bootstrap() /Users/timplunkett/.bin/drush_lib/includes/bootstrap.inc:308
    0.2669    7772920   6. _drush_bootstrap_drupal_root() /Users/timplunkett/.bin/drush_lib/includes/bootstrap.inc:185
    0.2669    7773016   7. drush_drupal_version() /Users/timplunkett/.bin/drush_lib/includes/bootstrap.inc:678
    0.2670    7775616   8. require_once('/Users/timplunkett/www/d8/core/vendor/autoload.php') /Users/timplunkett/.bin/drush_lib/includes/drupal.inc:30
    0.2672    7790592   9. ComposerAutoloaderInitDrupal8::getLoader() /Users/timplunkett/www/d8/core/vendor/autoload.php:7

EDIT: opened #2240803: Composer autoloader possibly out of date

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Xano’s picture

I just stumbled upon this change in contrib and found this issue after digging through the logs. I added a change record to help people discover this change in the future.