Reputation: 999
cURL seems to be significantly slower for me using PHP7.0.11 than it is when just running the request from the command line, or when run within PHP5.6.24. I'm testing it using the following code:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://i.imgur.com/H1zC601.gif");
curl_setopt($curl, CURLOPT_HTTPGET, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
var_dump(curl_getinfo($curl));
In both PHP5 and PHP7's CLI interpreter, and in PHP5 I get
array(26) {
["url"]=>
string(31) "https://i.imgur.com/H1zC601.gif"
["content_type"]=>
string(9) "image/gif"
["http_code"]=>
int(200)
["header_size"]=>
int(597)
["request_size"]=>
int(204)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(1.260002)
["namelookup_time"]=>
float(0.060424)
["connect_time"]=>
float(0.068474)
["pretransfer_time"]=>
float(0.089705)
["size_upload"]=>
float(0)
["size_download"]=>
float(34327108)
["speed_download"]=>
float(27243693)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(34327108)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0.098354)
["redirect_time"]=>
float(0)
["redirect_url"]=>
string(0) ""
["primary_ip"]=>
string(15) "151.101.124.193"
["certinfo"]=>
array(0) {
}
["primary_port"]=>
int(443)
["local_ip"]=>
string(14) "my IP"
["local_port"]=>
int(44555)
}
While when running PHP7, I get
array(26) {
["url"]=>
string(31) "https://i.imgur.com/H1zC601.gif"
["content_type"]=>
string(9) "image/gif"
["http_code"]=>
int(200)
["header_size"]=>
int(609)
["request_size"]=>
int(61)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(16.875167)
["namelookup_time"]=>
float(0.252648)
["connect_time"]=>
float(0.260626)
["pretransfer_time"]=>
float(0.280489)
["size_upload"]=>
float(0)
["size_download"]=>
float(34327108)
["speed_download"]=>
float(2034178)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(34327108)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0.288715)
["redirect_time"]=>
float(0)
["redirect_url"]=>
string(0) ""
["primary_ip"]=>
string(15) "151.101.124.193"
["certinfo"]=>
array(0) {
}
["primary_port"]=>
int(443)
["local_ip"]=>
string(14) "my IP"
["local_port"]=>
int(55559)
}
The important part being total_time, which is 1.3 seconds in PHP 5 but 16.9s in PHP 7.
When a timeout is set on the request, the number of bytes received is proportional to the timeout - the data is being transferred very slowly, rather than there being some obstruction that is preventing anything from being transferred for a while, then the whole thing being transferred in one go.
The server is running Debian, and I can't seem to reproduce the issue on my Fedora local machine.
Upvotes: 2
Views: 3013
Reputation: 1
You can see the php-curl versions like this:
php5 --ri curl
php7 --ri curl
Sometimes, The lower version can cause it.
Upvotes: 0
Reputation: 51
Same issue with PHP 7 on Debian Stretch. I noticed high sys-cpu times: 0.07s user 10.02s system 92% cpu 10.859 total
Issue was solved after disable transparent_hugepage:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
It does not effect curl downloads directly, but slows down php memory allocations. See: https://serverfault.com/questions/780555/how-to-troubleshoot-high-load-caused-by-php7
Upvotes: 2
Reputation: 1
i have same issue with curl onPHP 7.0.12 i run on both cli and fpm mode and download very slow speed, the speed degrade from 100Mbps to only 1~2 Mbps/s, i switch to php 5.6 and problem resolve, so it is not network issue,i am sure Hoping my info will help someone
Upvotes: 0
Reputation: 11942
To me, this just looks like a network latency issue or bandwidth issue. If you examine the speed_download
between the two you'll see that one is downloading significantly faster than the other. The first result using PHP 5/7-CLI shows "speed_download" => float(27243693)
while the second shows "speed_download" => float(2034178)
, while they both have an identical content length "download_content_length" => float(34327108)
.
So the first one is downloading a ~32.7MB file at ~25.9MB/sec, while the second is downloading the same file at ~1.9MB/sec. Obviously the second would take a lot longer.
Upvotes: 0