PHP with HTTP/2 support for CURL

Share on facebook
Share on linkedin
Share on twitter
Share on whatsapp
Share on email
PHP with HTTP/2 support for CURL

If you are our client most probably you know that has been some time we are running HTTP/2 support over LiteSpeed web server in all our cPanel shared web hosting services, which exponentially accelerate your web site loading, helping in your SEO ranking and also to keep visitors navigating in your web sites.

From now, we also support HTTP/2 with PHP, this is not for your web site loading but for PHP to perform HTTP/2 requests to remote servers via cURL functionality. This will add another layer of protection and also speedup the process using the next generation http protocol.

This is mainly a developer feature but we are sure in the near future most popular scripts developers will start taking advantages of it potential and this will effect in the popular scripts functioning like WordPress, Joomla, etc.

To check if this is working, you can either check the HTTP/2 feature in a phpinfo() at the cURL section. It should show as “Yes” (supported) or you can use the PHP code below in a file and access it with the url.

<?php

if (!defined(‘CURL_HTTP_VERSION_2_0’)) {

define(‘CURL_HTTP_VERSION_2_0’, 3);

}

$version = curl_version();

if ($version[“features”] & constant(‘CURL_VERSION_HTTP2’) !== 0) {

$url = “https://google.com/”;

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch,CURLOPT_HEADER,1);

curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0);

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

$response = curl_exec($ch);

if ($response !== false && strpos($response, “HTTP/2”) === 0) {

echo “HTTP/2 support!”;

} elseif ($response !== false) {

echo “No HTTP/2 support on server.”;

} else {

echo curl_error($ch);

}

curl_close($ch);

} else {

echo “No HTTP/2 support on client.”;

}

echo “\n”;

?>

Enjoy!

SHARE:

Share on facebook
Share on linkedin
Share on twitter
Share on whatsapp
Share on email

Table of Contents

Recent Posts

You May also be Interested

Avoid Your WordPress Sites Being Used For Phishing Or Spam

WordPress is the world’s most popular content management system (CMS) for a lot of very good reasons. You can setup a new WordPress site on a domain name very fast these days with the one click installation software that is available in cPanel with your premium web hosting service.

Using Your Domain Emails In The Gmail Interface

Do you have a Gmail account? How would you like to access email addresses for your domains via the Gmail interface? Gmail is very popular and there are millions of users. People like the Gmail interface and are happy to use it to access emails received to their Gmail email addresses.

How To Access A WordPress Installation With a Temporary Url

Many new customers ask us how they can test a WordPress installation that they have been hosting elsewhere and now they wish to move it to our Premium Hosting Services but how they can migrate, test the installation and have temporary wordpesss admin access in our system before point the domain definitely to our servers. They cannot figure out how to do this because WordPress installations are domain based.