Mercurial > SimpleWebPresenter
changeset 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 | df158368051e |
| children | e3f97bbf12f3 |
| files | Http.inc |
| diffstat | 1 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Http.inc Thu Dec 28 18:36:45 2017 +0100 +++ b/Http.inc Thu Dec 28 18:40:56 2017 +0100 @@ -97,13 +97,27 @@ */ static function getHeaders($url, $timeout = 1) { - $response = @http_head($url, array("timeout" => $timeout), $info); - - if (array_key_exists('error', $info) && $info['error']) { - throw new RequestException($info); + //Workaround when getHeaders doesn't work + if (false) { + $response = http_head($url, array("timeout" => $timeout), $info); + if (array_key_exists('error', $info) && $info['error']) { + throw new RequestException($info); + } + return self::headersToArray($response); + } + elseif (true) { + $rp = get_headers($url); + $response=array('' => array_shift ($rp)); + foreach($rp as $kv) { + $tmp=array_map('trim', explode(':', $kv, 2)); + $response[$tmp[0]]=$tmp[1]; + } + return $response; + } + else { + return array('' => 'HTTP/1.1 200 OK'); } - return self::headersToArray($response); } /**
