How to speed up using php curl?

I use php curl to interact with the data database of the counterparty

clipboard.png

curl

clipboard.png

I use the Google browser to see an item running for at least 3 seconds
I wonder if it"s a curl problem
because I think all the others are ms units. It"s not too slow.

curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);

I wrote a function
in this paragraph, so when I need any API, I will enable it
so sometimes it may take three to five
to take a long time.
is there any other way to make it faster?!

Mar.03,2021

I feel that my writing is not safe enough to hang up a small library. Such as Guzzle . But the code you give really doesn't show anything. Slow access has something to do with many factors, and it's not your little configuration that can get stuck.


Thank you for the invitation. You can grab a package and analyze it. There are many possibilities

.
  1. if it takes too long from executing curl to sending a dns request (if your target hostname is a domain name), then curl starts too slowly (I'm not familiar with php either. I don't know whether php executes curl fork)
  2. if the time from sending a dns request to getting a dns reply is too long, the domain name resolution is too slow. You can change to a faster dns or directly use ip
  3. if the time from sending a http request (which can be calculated from sending a syn packet) to getting a http reply is too long, it is that the query efficiency of the other party is low, and it is not your problem

you can also send the same request using chrome, depending on the timing.

of course, there may be other reasons, such as the Internet, which will be slow if your network is not in good condition.


the slow speed of CURL may be related to Expect:100-Continue. You can modify the code to try it out:
http://www.laruence.com/2011/.


is slow because of the problem of domain name resolution. You can first resolve the domain name to the corresponding IP

by using one of the methods of curl.
// http://baidu.com, ping  IP 
$url = 'http://220.15.23.5/';
// IP:https://baibu.com -> 220.15.23.5
 curl_setopt($ci, CURLOPT_HTTPHEADER, array('Host:baibu.com'));
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30709-2bd21.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30709-2bd21.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?