如何记录请求次数 php,php怎么判断http请求次数

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;

}

我要举报

如以上信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!

推荐资讯

大家都在看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值