当前位置:网站首页>php的curl函数模拟post数据提交,速度非常慢
php的curl函数模拟post数据提交,速度非常慢
2022-08-02 03:26:00 【陌潇】
前段时间做了一个项目,里面用到了快递查询接口。用的php 的curl post请求,发现此请求非常慢,效率非常低,就很恼火。还以为是快递接口那边的问题,试了下快递自己的请求非常快。于是研究了一波发现了一个解决办法,记录一下:
原本的请求是这样的,效率非常慢
//发送post请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$data = json_decode($result,true);
这样就得添加curl请求参数了:
- 强制协议为1.0
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- 强制使用IPV4协议解析域名
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
完满解决问题
边栏推荐
- 会计凭证概述、原始凭证、原始凭证的种类、原始凭证的基本内容、原始凭证的填制要求、原始凭证的审核
- uniapp | Compilation error after updating with npm update
- (2) Sequence structures, Boolean values of objects, selection structures, loop structures, lists, dictionaries, tuples, sets
- php函数漏洞总结
- What are the killer super powerful frameworks or libraries or applications for PHP?
- A code audit notes (CVE - 2018-12613 phpmyadmin file contains loopholes)
- 同态加密:CKKS原理之旋转(Rotation)
- 对账、结账、错账更正方法、划线更正法、红字更正法、补充登记法
- DNS详解
- 动力:2 vulnhub预排
猜你喜欢
随机推荐
By figure, a (complete code at the end)
hackmyvm: again walkthrough
链动2+1无限循环系统,2022年起盘成功率超高的模式
What are the killer super powerful frameworks or libraries or applications for PHP?
Alfa: 1 vulnhub walkthrough
英语每日打卡
uniapp | Problems with the use of the official map component
CTF入门之php文件包含
The learning path of a network security mouse - the basic use of nmap
Shuriken: 1 vulnhub walkthrough
PHP实现搜索框的自动反查提示
Activity
一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
[sebastian/diff] A historical change extension library for comparing two texts
动力:2 vulnhub预排
SATA M2 SSD 无法安装系统的解决方法
加密数字货币前传:从大卫·乔姆到中本聪
库存现金、现金管理制度、现金的账务处理、银行存款、银行存款的账务处理、银行存款的核对
4. PHP array and array sorting
Masashi: 1 vulnhub walkthrough









