Home  >  Article  >  Backend Development  >  How to solve the problem that curl transfers data too slowly in php

How to solve the problem that curl transfers data too slowly in php

WJ
WJOriginal
2020-06-09 17:07:103109browse

How to solve the problem that curl transfers data too slowly in php

How to solve the problem that curl transfers data too slowly in PHP?

If you use the curl_setopt function to process the remote webservice or crawl the page, sometimes you will encounter a very strange phenomenon. The first access speed is abnormally slow. Basically it takes 5s-10s for people to collapse.

But no matter how much I check, I can’t figure out where the problem lies. I recently found an article about how to deal with this problem.

Start by solving the problem:

1、curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //强制协议为1.0
2、curl_setopt($ch, CURLOPT_HTTPHEADER, array(''Expect: '')); //头部要送出'Expect: '
3、curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); //强制使用IPV4协议解析域名

Related references: php tutorial

The above is the detailed content of How to solve the problem that curl transfers data too slowly in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn