php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75471 PHP curl through proxy generating high CPU load
Submitted: 2017-10-31 22:37 UTC Modified: 2021-08-03 14:35 UTC
Votes:11
Avg. Score:4.8 ± 0.6
Reproduced:9 of 9 (100.0%)
Same Version:5 (55.6%)
Same OS:4 (44.4%)
From: alessandro dot ballini at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: cURL related
PHP Version: 7.0.25 OS: Ubuntu 16.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
41 - 5 = ?
Subscribe to this entry?

 
 [2017-10-31 22:37 UTC] alessandro dot ballini at gmail dot com
Description:
------------
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 HTTP proxy (I've tried many different ones). It is NOT happening with a SOCK5 proxy type.

With many threads running many requests at the same time, it soon becomes critical.

I'm using:

curl 7.55.1 (x86_64-conda_cos6-linux-gnu) libcurl/7.55.1 OpenSSL/1.0.2l zlib/1.2.11 libssh2/1.8.0
Release-Date: 2017-08-14
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy

Test script:
---------------
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, 'xxx');
curl_setopt($ch, CURLOPT_PROXYPORT, 'xxx');
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
//curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_URL, 'https://api.ipify.org?format=json');
curl_exec($ch);
curl_close($ch);
sleep(10);
} while (true);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-03 14:35 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-08-03 14:35 UTC] cmb@php.net
These options are passed through to libcurl almost verbatim, so
this doesn't look like a PHP issue, but rather an issue with
libcurl.  If it still happens with latest libcurl, consider to
report it upstream[1].

[1] <https://github.com/curl/curl/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 05:01:28 2024 UTC