OK, then the problem is not that you're using an old version of PHP. I'm not an expert on $_SERVER variables, but the manual says, in reference to $_SERVER['HTTP_HOST'], "Contents of the Host: header from the current request, if there is one." That last "if" suggests that there may not be a value under some circumstances.
The thing is, all 3 of these error messages relate to the same issue. The parse-url() function isn't working because all it's getting is "http://", so there's nothing to parse. It apparently IS getting your $protocol value. But the messages about "undefined index" are talking about not finding those parts of the $_SERVER global
array. The $_SERVER array can have dozens of indexes, with a value corresponding to each index. You can find all of the possible indexes at
http://php.net/manual/en/reserved.variables.server.php. So that's the root of your problem. Only I don't know why those 2 indexes would be missing. Sorry.
I just had a thought: you ARE testing this by calling this script from a browser, aren't you? Because if you were just trying to execute the PHP code on its own, there would BE NO REQUEST, thus no values or even indexes in the $_SERVER array.