curl-and-php
PHP curl with proxy and high CPU usage
Date: Mon, 30 Oct 2017 16:00:29 +0100
Hi everyone,
I've been searching a bit for known bugs, but I could not find anything
related to proxies and CPU.
After investigating the reasons for the high CPU load generated by an
application sending many curl requests with 20 parallel PHP-cli scripts,
I've found out the main reason is the PROXY option set to the cURL handle.
The following code is generating a 0.5-1.5% CPU load at the moment of
curl_exec when run without the proxy and 12-25% when using any proxy
(I've tried many different ones).
With many threads running many requests at the same time, it soon
becomes critical.
Any experience or suggestion about this? Should I open a curl bug?
I'm using:
Ubuntu 16.04
PHP 7.0.22
curl 7.55.1
Thanks,
Alessandro
$address = 'xxx';
$port = 'xxx';
$url = 'https://api.ipify.org?format=json';
do {
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_ENCODING, 'identity');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_PROXY, $address);
curl_setopt($ch, CURLOPT_PROXYPORT, $port);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
curl_close($ch);
sleep(10);
} while (true);
_______________________________________________
https://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2017-10-30