
- PHP - Home
- PHP - Roadmap
- PHP - Introduction
- PHP - Installation
- PHP - History
- PHP - Features
- PHP - Syntax
- PHP - Hello World
- PHP - Comments
- PHP - Variables
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ and $$ Variables
- PHP - Constants
- PHP - Magic Constants
- PHP - Data Types
- PHP - Type Casting
- PHP - Type Juggling
- PHP - Strings
- PHP - Boolean
- PHP - Integers
- PHP - Files & I/O
- PHP - Maths Functions
- PHP - Heredoc & Nowdoc
- PHP - Compound Types
- PHP - File Include
- PHP - Date & Time
- PHP - Scalar Type Declarations
- PHP - Return Type Declarations
- PHP - Operators
- PHP - Arithmetic Operators
- PHP - Comparison Operators
- PHP - Logical Operators
- PHP - Assignment Operators
- PHP - String Operators
- PHP - Array Operators
- PHP - Conditional Operators
- PHP - Spread Operator
- PHP - Null Coalescing Operator
- PHP - Spaceship Operator
- PHP Control Statements
- PHP - Decision Making
- PHP - If…Else Statement
- PHP - Switch Statement
- PHP - Loop Types
- PHP - For Loop
- PHP - Foreach Loop
- PHP - While Loop
- PHP - Do…While Loop
- PHP - Break Statement
- PHP - Continue Statement
- PHP Arrays
- PHP - Arrays
- PHP - Indexed Array
- PHP - Associative Array
- PHP - Multidimensional Array
- PHP - Array Functions
- PHP - Constant Arrays
- PHP Functions
- PHP - Functions
- PHP - Function Parameters
- PHP - Call by value
- PHP - Call by Reference
- PHP - Default Arguments
- PHP - Named Arguments
- PHP - Variable Arguments
- PHP - Returning Values
- PHP - Passing Functions
- PHP - Recursive Functions
- PHP - Type Hints
- PHP - Variable Scope
- PHP - Strict Typing
- PHP - Anonymous Functions
- PHP - Arrow Functions
- PHP - Variable Functions
- PHP - Local Variables
- PHP - Global Variables
- PHP Superglobals
- PHP - Superglobals
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP File Handling
- PHP - File Handling
- PHP - Open File
- PHP - Read File
- PHP - Write File
- PHP - File Existence
- PHP - Download File
- PHP - Copy File
- PHP - Append File
- PHP - Delete File
- PHP - Handle CSV File
- PHP - File Permissions
- PHP - Create Directory
- PHP - Listing Files
- Object Oriented PHP
- PHP - Object Oriented Programming
- PHP - Classes and Objects
- PHP - Constructor and Destructor
- PHP - Access Modifiers
- PHP - Inheritance
- PHP - Class Constants
- PHP - Abstract Classes
- PHP - Interfaces
- PHP - Traits
- PHP - Static Methods
- PHP - Static Properties
- PHP - Namespaces
- PHP - Object Iteration
- PHP - Encapsulation
- PHP - Final Keyword
- PHP - Overloading
- PHP - Cloning Objects
- PHP - Anonymous Classes
- PHP Web Development
- PHP - Web Concepts
- PHP - Form Handling
- PHP - Form Validation
- PHP - Form Email/URL
- PHP - Complete Form
- PHP - File Inclusion
- PHP - GET & POST
- PHP - File Uploading
- PHP - Cookies
- PHP - Sessions
- PHP - Session Options
- PHP - Sending Emails
- PHP - Sanitize Input
- PHP - Post-Redirect-Get (PRG)
- PHP - Flash Messages
- PHP AJAX
- PHP - AJAX Introduction
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML
- PHP - XML Introduction
- PHP - Simple XML Parser
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Login Example
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP Advanced
- PHP - MySQL
- PHP.INI File Configuration
- PHP - Array Destructuring
- PHP - Coding Standard
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Try…Catch
- PHP - Bugs Debugging
- PHP - For C Developers
- PHP - For PERL Developers
- PHP - Frameworks
- PHP - Core PHP vs Frame Works
- PHP - Design Patterns
- PHP - Filters
- PHP - JSON
- PHP - Exceptions
- PHP - Special Types
- PHP - Hashing
- PHP - Encryption
- PHP - is_null() Function
- PHP - System Calls
- PHP - HTTP Authentication
- PHP - Swapping Variables
- PHP - Closure::call()
- PHP - Filtered unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - Expectations
- PHP - Use Statement
- PHP - Integer Division
- PHP - Deprecated Features
- PHP - Removed Extensions & SAPIs
- PHP - PEAR
- PHP - CSRF
- PHP - FastCGI Process
- PHP - PDO Extension
- PHP - Built-In Functions
PHP cURL curl_version() Function
The PHP cURL curl_version() function is used to get the information about the cURL version installed. It returns an associative array with various details about cURL.
Syntax
Below is the syntax of the PHP cURL curl_version() function −
array curl_version ()
Parameters
This function does not accepts any parameter.
Return Value
The curl_version() function returns an associative array which contains various information like −
1. version_number − The cURL version number as an integer.
2. version − The cURL version number as a string.
3. ssl_version_number − The OpenSSL version number as an integer.
4. ssl_version − The OpenSSL version number as a string.
5. libz_version − The libz version as a string.
6. host − Information about the host where cURL was built.
7. age − The age of the cURL library.
8. features − It is a bitmask of features.
9. protocols − An array of supported protocols.
PHP Version
First introduced in core PHP 4.0.2, the curl_version() function continues to function easily in PHP 5, PHP 7, and PHP 8.
Example 1
First we will show you the basic example of the PHP cURL curl_version() function to get the information about version.
<?php // Get cURL version information $curl_info = curl_version(); // Print the cURL version information echo 'cURL version: ' . $curl_info['version'] . "\n"; echo 'SSL version: ' . $curl_info['ssl_version'] . "\n"; echo 'libz version: ' . $curl_info['libz_version'] . "\n"; ?>
Output
Here is the outcome of the following code −
cURL version: 7.53.1 SSL version: OpenSSL/1.1.1t libs version: 1.2.11
Example 2
Now the below code retrieves cURL version information using the curl_version() function.
<?php // Get cURL version information $curl_info = curl_version(); // Print supported protocols echo 'Supported protocols: ' . implode(', ', $curl_info['protocols']) . "\n"; ?>
Output
This will create the below output −
Supported protocols: dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp
Example 3
In the below PHP code we will use the curl_version() function to check the version and features of the installed cURL.
<?php // Get the curl version array $ver = curl_version(); // To check for features in the curl build $bitfields = Array( 'CURL_VERSION_IPV6', 'CURL_VERSION_KERBEROS4', 'CURL_VERSION_SSL', 'CURL_VERSION_LIBZ' ); foreach($bitfields as $feature) { echo $feature . ($ver['features'] & constant($feature) ? ' It matches' : ' It does not match'); echo '<br>'; echo PHP_EOL; } ?>
Output
This will generate the below output −
CURL_VERSION_IPV6 It matches CURL_VERSION_KERBEROS4 It does not match CURL_VERSION_SSL It matches CURL_VERSION_LIBZ It matches
Example 4
In the following example, we are using the curl_version() function to get the fetch the primary IP address with the number of redirects.
<?php // Get cURL version information $curl_info = curl_version(); // Print all cURL version information foreach ($curl_info as $key => $value) { if (is_array($value)) { echo $key . ': ' . implode(', ', $value) . "<br>"; } else { echo $key . ': ' . $value . "<br>"; } } ?>
Output
Following is the output of the above code −
version_number: 472321 age: 3 features: 2671133 ssl_version_number: 0 version: 7.53.1 host: x86_64-apple-darwin14.5.0 ssl_version: OpenSSL/1.1.1t libz_version: 1.2.11 protocols: dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp ares: ares_num: 0 libidn: iconv_ver_num: 0 libssh_version:
Summary
The curl_version() method is a built-in method in PHP which allows you to check the information about the cURL version installed. And we have seen four examples to see the usage of the function in different cases.