Convert Guzzle requests to curl commands with namshi/cuzzle

The other day the namshi/cuzzle PHP pacakge came in really handy.

This library let’s you dump a Guzzle request to a cURL command for debug and log purposes

This way I could test some things on the CLI, and easily share these tests with all my colleagues, including those without PHP installed.

use Namshi\Cuzzle\Formatter\CurlFormatter;
use GuzzleHttp\Message\Request;

$request = new Request('GET', 'example.local');
$options = [];

echo (new CurlFormatter())->format($request, $options);
// ~> curl example.local -X GET -A 'GuzzleHttp/6.4.1 curl/7.71.1 PHP/7.4.9'

Also comes with a Monolog formatter to easily log the resulting curl commands in your log files. Do keep in mind that you might be leaking sensitive information (passwords/tokens) that way …

Installation per Composer:

composer require namshi/cuzzle

Cuzzle, cURL command from Guzzle requests →

Guzzle: Fake a Response using a `MockHandler`

Now this will come in handy for testing:

Via Freek

Avoid Guzzle 6.5.0 (aka How to fix “Use of undefined constant INTL_IDNA_VARIANT_UTS46” on CentOS 6)

There’s a bug in Guzzle 6.5.0 in which it does not play nice with systems that have an older ICU library (which PHP’s Intl extension uses). CentOS 6 for example ships with a very old ICU version, without any (offical) means of updating it. The bug should be fixed in (the unreleased) Guzzle 6.5.1.

It is recommended that all PHP projects avoid Guzzle 6.5.0, by requiring Guzzle as follows:

composer require guzzlehttp/guzzle:'>=6.3.0 <6.5.0 || ^6.5.1'

~

A client of mine reported that he could no longer upload photos to an S3 bucket from within his CraftCMS website. The upload failed with the following message:

Use of undefined constant INTL_IDNA_VARIANT_UTS46 - assumed 'INTL_IDNA_VARIANT_UTS46'

As I had just updated the dependencies of that project, I checked the diff of the composer.json and saw that Guzzle got bumped to version 6.5.0

~

Although the release notes for 6.5.0 somehow don't mention it, there's a commit in 6.5.0 that reads “Internationalized domain name (IDN) support (#2286)”. In that commit you can find usage of PHP's INTL_IDNA_VARIANT_UTS46 constant.

Checking the list of Intl provided constants, there's this small note next to INTL_IDNA_VARIANT_UTS46:

Available as of ICU 4.6.

And, as it turns out, the installed version on the CentOS 6 server that serves the project is lower than 4.6:

$ yum list installed icu
…
Installed Packages
icu.x86_64              4.2.1-14.el6

Unfortunately there's no official way of updating ICU to a more recent version on CentOS 6 (*), so a fix needs to happen on Guzzle's end. An issue has been reported with Guzzle and the fix should land in version 6.5.1.

💁‍♂️ (*) You could try installing this unofficial ICU release from the Remi Repository, but then you'd also need to recompile PHP. This isn't always possible to do – e.g. in cases where it's not your server – and would take us way off.

~

If you – as a PHP developer – are affected by this issue right now, you can work around it by avoiding Guzzle 6.5.0. To do so, require Guzzle as follows:

composer require guzzlehttp/guzzle:'>=6.3.0 <6.5.0 || ^6.5.1'

If you've developed a project which relies on Guzzle, it's recommended to implement this change, just like CraftCMS does, so that your users – who might be running CentOS 6 – are not affected by it.

~

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

☕️ Buy me a Coffee (€4)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.