当前位置:网站首页>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 );
完满解决问题
边栏推荐
- Activity
- (5) Modules and packages, encoding formats, file operations, directory operations
- What are the killer super powerful frameworks or libraries or applications for PHP?
- Phonebook
- 2021-09-04 最简单的Golang定时器应用以及最简单的协程入门儿
- A network security guinea pig's learning path - scripting of advanced usage of nmap
- 什么是广告电商商业模式?这几个门派告诉你
- GreenOptic: 1 vulnhub walkthrough
- 战场:3(双子叶植物)vulnhub走读
- (3) 字符串
猜你喜欢
随机推荐
学IT,找工作——反转链表
cmake安装到指定目录
链动2+1模式开发系统
hackmyvm: again walkthrough
2. PHP variables, output, EOF, conditional statements
Anaconda报错:An unexpected error has occurred. Conda has prepared the above report 解决办法
A network security guinea pig's learning path - scripting of advanced usage of nmap
2021-09-04 最简单的Golang定时器应用以及最简单的协程入门儿
How to log in to Alibaba Cloud server using the admin account
v-bind usage: class dynamic binding object array style style and function method
动力:2 vulnhub预排
Google Hacking
什么是广告电商商业模式?这几个门派告诉你
SATA M2 SSD 无法安装系统的解决方法
ES6 array extension methods map, filter, reduce, fill and array traversal for…in for…of arr.forEach
考(重点理解哪些属于其他货币资金)、其他货币资金的内容、其他货币资金的账务处理(银行汇票存款、银行本票存款、信用卡存款、信用证保证金存款、存出投资款、外埠存款)
Alfa: 1 vulnhub walkthrough
重点考:金融资产概述、交易性金融资产的概念、交易性金融资产的账务处理(取得、持有。出售)、
File upload vulnerability
The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)









