Php 处理https的函数sendToHost()的替代方法

Php 处理https的函数sendToHost()的替代方法,php,https,ping,Php,Https,Ping,我一直在使用一个名为sendtoost的函数,该函数用于使用GET字符串ping服务器并返回响应 # Example of GET string: # sub.domain.com/api.php?a=1&b=2&c=3 $var = sendToHost('sub.domain.com','get','/api.php','a=1&b=2&c=3'); 但是,它无法处理发送到安全服务器(https)的问题 有人知道php函数可以替代sendToHost吗

我一直在使用一个名为sendtoost的函数,该函数用于使用GET字符串ping服务器并返回响应

#  Example of GET string:
#  sub.domain.com/api.php?a=1&b=2&c=3
$var = sendToHost('sub.domain.com','get','/api.php','a=1&b=2&c=3');
但是,它无法处理发送到安全服务器(https)的问题

有人知道php函数可以替代sendToHost吗

以下是SendToHost代码:

/* sendToHost
 * ~~~~~~~~~~
 * Params:
 *   $host - Just the hostname.  No http:// or /path/to/file.html portions
 *   $method - get or post, case-insensitive
 *   $path - The /path/to/file.html part
 *   $data - The query string, without initial question mark
 *   $useragent - If true, 'MSIE' will be sent as the User-Agent (optional)
 *
 * Examples:
 *   sendToHost('www.google.com','get','/search','q=php_imlib');
 *   sendToHost('www.example.com','post','/some_script.cgi',
 *              'param=First+Param&second=Second+param');
 */
function sendToHost($host,$method,$path,$data,$useragent=0)
{
    // Supply a default method of GET if the one passed was empty
    if (empty($method))
        $method = 'GET';
    $method = strtoupper($method);
    $fp = fsockopen($host,80);
    if ($method == 'GET')
        $path .= '?' . $data;
    fputs($fp, "$method $path HTTP/1.1\r\n");
    fputs($fp, "Host: $host\r\n");
    fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
    if ($method == 'POST')
        fputs($fp, "Content-length: " . strlen($data) . "\r\n");
    if ($useragent)
        fputs($fp, "User-Agent: MSIE\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    if ($method == 'POST')
        fputs($fp, $data);

    while (!feof($fp))
        $buf .= fgets($fp,128);
    fclose($fp);
    return $buf;
}

谢谢。

你试过用卷发吗?它支持ssl,在GNU/Linux下运行良好。

下面可以找到两个有用的函数: