Re: com web/php: use streams instead of raw sockets. solves the problem that the old implementation doesn't support ssl: include/posttohost.inc
| From: | Hannes Magnusson | Date: | Sat, 28 Jul 2012 13:09:23 +0000 |
| Subject: | Re: com web/php: use streams instead of raw sockets. solves the problem that the old implementation doesn't support ssl: include/posttohost.inc | ||
| References: | 1 | Groups: | php.webmaster |
| Request: | Send a blank email to php-webmaster+get-14020@lists.php.net to get a copy of this message | ||
On Sat, Jul 28, 2012 at 2:30 AM, Ferenc Kovacs <tyrael@php.net> wrote:
> Commit: ac801d89cc224ed19ff44d3672110a49922e1b22
> Author: Ferenc Kovacs <tyra3l@gmail.com> Sat, 28 Jul 2012 03:30:50 +0200
> Parents: 1e75e669f2806fe2f0e6557fa01d55fe94d4144d
> Branches: master
>
> Link:
> http://git.php.net/?p=web/php.git;a=commitdiff;h=ac801d89cc224ed19ff44d3672110a49922e1b22
>
> Log:
> use streams instead of raw sockets. solves the problem that the old implementation doesn't
> support ssl
>
> Changed paths:
> M include/posttohost.inc
>
>
> Diff:
> diff --git a/include/posttohost.inc b/include/posttohost.inc
> index 340ecb0..1e37d5b 100644
> --- a/include/posttohost.inc
> +++ b/include/posttohost.inc
> @@ -10,50 +10,17 @@
>
> function posttohost($url, $data)
> {
> - // Get parts of URL
> - $url = parse_url($url);
> - if (!$url) { return "couldn't parse url"; }
> -
> - // Provide defaults for port and query string
> - if (!isset($url['port'])) { $url['port'] = ""; }
> - if (!isset($url['query'])) { $url['query'] = ""; }
> + $data = http_build_query($data);
>
> - // Build POST string
> - $encoded = "";
> - foreach ($data as $k => $v) {
> - $encoded .= ($encoded ? "&" : "");
> - $encoded .= rawurlencode($k) . "=" . rawurlencode($v);
> - }
> + $opts = array(
> + 'method' => 'POST',
> + 'header' => 'Content-type: application/x-www-form-urlencoded',
> + 'content' => $data,
> + );
>
> - // Open socket on host
> - $fp = @fsockopen($url['host'], $url['port'] ? $url['port'] :
> 80);
> - if (!$fp) { return "failed to open socket to {$url['host']}"; }
> + $ctx = stream_context_create(array('http' => $opts));
>
> - // Send HTTP 1.0 POST request to host
> - fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'],
> $url['query'] ? "?" : "", $url['query']));
> - fputs($fp, "Host: {$url['host']}\n");
> - fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
> - fputs($fp, "Content-length: " . strlen($encoded) . "\n");
> - fputs($fp, "Connection: close\n\n");
> - fputs($fp, "$encoded\n");
> + $response_body = @file_get_contents($url, false, $ctx);
The reason why we hadn't done this was because the mirrors were
running all sorts of older versions.
Have you verified everyone is running newer version?
-Hannes