欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php 异步请求

程序员文章站 2024-04-03 08:42:10
...
/**
* 发送HTTP请求并获得响应
* @param url 请求的url地址
* @param param 发送的http参数
*/
function makeRequest($url, $param, $httpMethod = 'GET') {
$oCurl = curl_init();
if (stripos($url, "https://") !== FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
}

if ($httpMethod == 'GET') {
curl_setopt($oCurl, CURLOPT_URL, $url . "?" . http_build_query($param));
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
} else {
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_POST, 1);
curl_setopt($oCurl, CURLOPT_POSTFIELDS, http_build_query($param));
}

$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
} else {
return FALSE;
}
}

AD:真正免费,域名+虚机+企业邮箱=0元