选择语言 :

 Core_HttpCall::_create_curl

创建一个CURL对象

curl_init() Core_HttpCall::_create_curl( string $host , int $port , $url , $path_info , $timeout , $vars , $mictime , $rstr )

参数列表

参数 类型 描述 默认值
$host string $url URL地址
$port int $timeout 超时时间
$url unknown
$path_info unknown
$timeout unknown
$vars unknown
$mictime unknown
$rstr unknown
返回值
  • curl_init()
File: ./core/classes/httpcall.class.php
protected static function _create_curl($host, $port, $url, $path_info, $timeout, $vars, $mictime, $rstr)
{
    if (preg_match('#^(http(?:s)?)\://([^/\:]+)(\:[0-9]+)?/#', $url.'/', $m))
    {
        $url = $m[1].'://'.$host.$m[3].'/'.substr($url, strlen($m[0]));
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, max(HttpCall::$connecttimeout_ms, $timeout));
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, HttpCall::$connecttimeout_ms);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
    curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 86400);

    if ( preg_match('#^https://#i', $url) )
    {
        if (!$port)$port = 443;
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    }
    else
    {
        if (!$port)$port = 80;
    }

    # 生成一个HASH
    $hash = self::get_hash($vars, $rstr, $mictime, $path_info .'_'. (IS_ADMIN_MODE?1:0) .'_'. (IS_REST_MODE?1:0));

    $header = array
    (
        'Expect:',
        'Host: '.$m[2],
        'X-Myqee-System-Hash: '.$hash,
        'X-Myqee-System-Time: '.$mictime,
        'X-Myqee-System-Rstr: '.$rstr,
        'X-Myqee-System-Pathinfo: '.$path_info,
        'X-Myqee-System-Project: '.Core::$project,
        'X-Myqee-System-Isadmin: '.(IS_ADMIN_MODE?1:0),
        'X-Myqee-System-Isrest: '.(IS_REST_MODE?1:0),
        'X-Myqee-System-Debug: '.(IS_DEBUG?1:0),
    );

    curl_setopt($ch, CURLOPT_PORT, $port);
    curl_setopt($ch, CURLOPT_USERAGENT, 'MyQEE System Call');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    return $ch;
}