comparison Http.inc @ 120:111770d32c2e

Workaround for pecl_http not working with PHP7
author Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no>
date Thu, 28 Dec 2017 18:40:56 +0100
parents 2370f4450983
children 51b53cd01080
comparison
equal deleted inserted replaced
119:df158368051e 120:111770d32c2e
95 * @param $timeout float number of seconds to wait before timeout 95 * @param $timeout float number of seconds to wait before timeout
96 * @return an associative array of all headers returned 96 * @return an associative array of all headers returned
97 */ 97 */
98 static function getHeaders($url, $timeout = 1) 98 static function getHeaders($url, $timeout = 1)
99 { 99 {
100 $response = @http_head($url, array("timeout" => $timeout), $info); 100 //Workaround when getHeaders doesn't work
101 101 if (false) {
102 if (array_key_exists('error', $info) && $info['error']) { 102 $response = http_head($url, array("timeout" => $timeout), $info);
103 throw new RequestException($info); 103 if (array_key_exists('error', $info) && $info['error']) {
104 throw new RequestException($info);
105 }
106 return self::headersToArray($response);
107 }
108 elseif (true) {
109 $rp = get_headers($url);
110 $response=array('' => array_shift ($rp));
111 foreach($rp as $kv) {
112 $tmp=array_map('trim', explode(':', $kv, 2));
113 $response[$tmp[0]]=$tmp[1];
114 }
115 return $response;
116 }
117 else {
118 return array('' => 'HTTP/1.1 200 OK');
104 } 119 }
105 120
106 return self::headersToArray($response);
107 } 121 }
108 122
109 /** 123 /**
110 * Performs a post to an URI for headers 124 * Performs a post to an URI for headers
111 * 125 *