Search
-
Recent Posts
Tags
adwords amazon analytics api apple aws blog chrome chromium cloud Design dropbox ec2 email error facebook firefox google google-apps homebrew ipad javascript jQuery linux lion mac microsoft mysql osx os x paypal php plugin quicksilver raspberry pi scam social spam twitter ubuntu unix video windows woo wordpress
Tag Archives: pecl
How to use http_build_url with pecl_http version 2.0 with PHP 5.4, 5.5, and 5.6
The old way to use http_build_url This is how to use http_build_url with pecl_http version 1.x: $parse = parse_url(‘http://example.com/index.asp?test=123#hash’); print_r($parse); # # Yields a result of: # # Array # ( # [scheme] => http # [host] => example.com # [path] => /index.asp # [query] => test=123 # [fragment] => hash # ) $url = http_build_url($parse); echo $url; # # Yields a result of: # # http://example.com/index.asp?test=123#hash The new way to use http_build_url with pecl_http version 2.x: This functionality has now moved into the http\Url class: $parse = parse_url(‘http://example.com/index.asp?test=123#hash’); print_r($parse); # # Yields a result of: # # Array # ( # [scheme] => http # [host] => example.com # [path] => /index.asp # [query] => test=123 # [fragment] => hash # ) $url = new \http\Url($parse); echo $url->toString(); # # Yields a result of: # # http://example.com/index.asp?test=123#hash #
How to use http_get_request_headers with PECL_HTTP version 2
If you’re using the version 2 pecl_http (possibly version 2.0.6?) on your webserver, perhaps Ubuntu or CentOS, with PHP5, maybe 5.3, 5.4, or 5.5, you may have noticed that after getting it all installed and adding this to your php.ini file: extension=raphf.so extension=propro.so extension=http.so But then when you try and use the function get_request_headers() you end up getting: PHP Fatal error: Call to undefined function http_get_request_headers() Well, when this extension switched to pecl/http v2 it changed a lot of things, and global functions was one of them. It now uses namespaces, and so instead of using http_get_request_headers() you’ll need to use something like this: $headers = \http\Env::getRequestHeader(); print_r($headers); The check out the docs for more details on how to use the new function, basically you’ll see getRequestHeader: Retrieve one or all headers of the current HTTP request. Parameters: Optional string $header_name The key of a header to retrieve. Returns: NULL, if $header_name was not found string, the compound header when $header_name was found array of all headers if $header_name was not specified