/** * php异步请求 * * @param $host string 主机地址 * @param $path string 路径 * @param $param array 请求参数 * @return string */ public static function asyncRequest($host, $path, $param = array()) { $query = isset($param) ? http_build_query($param) : ''; $port = 80; $errno = 0; $errstr = ''; $timeout = 10; $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fp) { return '连接失败'; } if ($errno || !$fp) { return $errstr; } $out = "POST " . $path . " HTTP/1.1\r\n"; $out .= "host:" . $host . "\r\n"; $out .= "content-length:" . strlen($query) . "\r\n"; $out .= "content-type:application/x-www-form-urlencoded\r\n"; $out .= "connection:close\r\n\r\n"; $out .= $query; $result = @fputs($fp, $out); @fclose($fp); return $result; }