Browse Source

Allow curl to use HTTP/2

pull/1/head
Martijn van der Ven 3 years ago
committed by GitHub
parent
commit
fe272902e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      src/p3k/HTTP/Curl.php

+ 15
- 0
src/p3k/HTTP/Curl.php View File

@ -5,6 +5,7 @@ class Curl implements Transport {
protected $_timeout = 4;
protected $_max_redirects = 8;
static protected $_http_version = null;
public function set_max_redirects($max) {
$this->_max_redirects = $max;
@ -79,6 +80,20 @@ class Curl implements Transport {
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->_max_redirects);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, round($this->_timeout * 1000));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000);
curl_setopt($ch, CURLOPT_HTTP_VERSION, $this->_http_version());
}
private function _http_version() {
if (static::$_http_version !== null)
return static::$_http_version;
if (defined('CURL_HTTP_VERSION_2')) { // PHP 7.0.7
static::$_http_version = CURL_HTTP_VERSION_2;
} else if (defined('CURL_HTTP_VERSION_2_0')) { // Recommended in online articles
static::$_http_version = CURL_HTTP_VERSION_2_0;
} else { // Linked curl might be newer than PHP, send (current) INT value anyway.
static::$_http_version = 3;
}
return static::$_http_version;
}
public static function error_string_from_code($code) {

Loading…
Cancel
Save