当前位置:网站首页>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 );
完满解决问题
边栏推荐
猜你喜欢
广告电商「私域打工人」职业前景:你离月薪6万,还差多远?
Eric靶机渗透测试通关全教程
(1) the print () function, escape character, binary and character encoding, variables, data type, the input () function, operator
GreenOptic: 1 vulnhub walkthrough
ES6 iterator explanation example
ES6 array extension methods map, filter, reduce, fill and array traversal for…in for…of arr.forEach
命令执行漏洞
CTF introductory notes ping
v-bind usage: class dynamic binding object array style style and function method
3000字入门图神经网络
随机推荐
CTF之xxe
Google Hacking
重点考:金融资产概述、交易性金融资产的概念、交易性金融资产的账务处理(取得、持有。出售)、
mysql 原生语句点滴学习记录
(3) 字符串
hackmyvm: juggling walkthrough
Shuriken: 1 vulnhub walkthrough
同态加密:CKKS原理之旋转(Rotation)
php函数漏洞总结
The learning path of a network security mouse - the basic use of nmap
Cookie is used to collect the admin privileges CTF foundation problem
WeChat applet development video loading: [Rendering layer network layer error] Failed to load media
(不重点考)试算平衡的分类
hackmyvm: controller walkthrough
Basic use of v-on, parameter passing, modifiers
CTF introductory notes ping
Uniapp | compatibility problems in the development of (to be continued)
After Alibaba Cloud sets up domain name resolution redirection, I cannot use Chrome to access it
[sebastian/diff] A historical change extension library for comparing two texts
C language uses stack to calculate infix expressions