php怎么判断http请求次数
关注:74 答案:1 手机版
解决时间 2021-01-31 15:58
提问者安分守己的小青春
2021-01-31 11:52
php怎么判断http请求次数
最佳答案
二级知识专家阳忆青希
2021-01-31 12:20
摘一段代码给你。请参考。
function postCurlDatas($get_url, $postdata = '', $other_options = array()) {
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $get_url); // 要访问的地址
// curl_setopt($curl, CURLOPT_USERAGENT, $GLOBALS ['user_agent']);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_DNS_USE_GLOBAL_CACHE, false); // 禁用全局DNS缓存
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); //此参数必须在上面的参数之后,切记
if (!empty($other_options['userpwd'])) {
curl_setopt($curl, CURLOPT_USERPWD, $other_options['userpwd']);
}
if (!empty($other_options['time_out'])) {
curl_setopt($curl, CURLOPT_TIMEOUT, $other_options['time_out']);
} else {
curl_setopt($curl, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
}
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$ret = curl_exec($curl); // 执行操作
if ($ret === false) {
echo 'Curl error: ' . curl_error($curl);
curl_close($curl);
return false;
}
if ($other_options['return_detail'] == true) {
$detail = curl_getinfo($curl);
if (is_array($detail)) {
$detail['return_content'] = $ret;
}
$ret = $detail;
}
curl_close($curl); // 关闭CURL会话
return $ret;
}
我要举报
如以上信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
推荐资讯
大家都在看