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

ext/curl: Add feature_info assoc array to curl_version() #13439

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

Ayesh
Copy link
Contributor

@Ayesh Ayesh commented Feb 20, 2024

The phpinfo() section of the Curl extension lists individual features supported by the particular ext-Curl + libcurl build. However, the curl_version() function return values do not indicate the same level of details.

curl_version() has a protocols key that returns an array of all protocols supported by the build. But the features key is a bitmask of all the features. Checking the availability of certain feature requires knowing the corresponding CURL_VERSION constant, and checking the availability of the constant and a bitmask check for it in the features value.

For example, to determine HTTP2 support, it requires evaluating:

defined('CURL_VERSION_HTTP2') && (curl_version()['features'] & CURL_VERSION_HTTP2 === CURL_VERSION_HTTP2)

To make feature availability checks more intuitive, this adds a new feature_list key to curl_version() output array.

With it, checking for individual features availability is easier, and does not require inspecting the availability of the CURL_VERSION constant and the features key.

!empty(curl_version()['feature_list']['HTTP2']);

@Ayesh Ayesh force-pushed the curl-version-info-features branch 4 times, most recently from b5eb1f8 to 17c07f3 Compare February 20, 2024 10:43
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me

ext/curl/interface.c Outdated Show resolved Hide resolved
The `phpinfo()` section of the Curl extension lists individual features
supported by the particular ext-Curl + libcurl build. However, the
`curl_version()` function return values do not indicate the same level of
details.

`curl_version()` has a `protocols` key that returns an array of all protocols
supported by the build. But the `features` key is a bitmask of all the features.
Checking the availability of certain feature requires knowing the corresponding
`CURL_VERSION` constant, and checking the availability of the constant and a
bitmask check for it in the `features` value.

For example, to determine HTTP2 support, it requires evaluating:

```php
defined('CURL_VERSION_HTTP2') && (curl_version()['features'] & CURL_VERSION_HTTP2 === CURL_VERSION_HTTP2)
```

To make feature availability checks more intuitive, this adds a new
`feature_list` key to `curl_version()` output array.

With it, checking for individual features availability is easier, and does
not require inspecting the availability of the `CURL_VERSION` constant and
the `features` key.

```php
!empty(curl_version()['feature_list']['HTTP2']);
```
@Girgias Girgias merged commit ba0f9fb into php:master Feb 21, 2024
10 checks passed
@Ayesh
Copy link
Contributor Author

Ayesh commented Feb 21, 2024

Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants