cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

fnctl() taking a looong time

From: Hoggins! <fuckspam_at_wheres5.com>
Date: Tue, 21 Jun 2016 14:18:53 +0200

Hello list,

First post here, I have an issue.

I'm using PHP 5.6.22, and my system has libcurl-7.43.0-7 on my Fedora 23
server.
I'm running a script that is looping through events received on a
socket. Each time such an event is received, it triggers a series of
cURL requests with the following code :

                // LOOP START
                [...]
                $params_url = http_build_query($params, '', '&');
                $ch = curl_init();
                   $options = array(
                        CURLOPT_TCP_NODELAY => 1,
/*****************************************************************/
                        CURLOPT_FORBID_REUSE => 1, /* added
these two, having read that it could help. No luck */
                                                               
/*****************************************************************/
                        CURLOPT_URL => $url,
                        CURLOPT_RETURNTRANSFER => TRUE,
                        CURLOPT_POST => TRUE,
                        CURLOPT_POSTFIELDS => $params_url,
                        CURLINFO_HEADER_OUT => TRUE,
                        CURLOPT_CONNECTTIMEOUT => 5,
                        CURLOPT_TIMEOUT => 10,
                );
                curl_setopt_array($ch, $options);
                $data = curl_exec($ch);
                curl_close($ch);
                [...]
                // LOOP END

My problem is that over time, the cURL requests take more and more time
to complete. This is a *new* behavior on my code, but I'm not absolutely
sure of where it comes from, hence my call for help.
I can see that it seems to be stalled for a while under a specific call
using strace (strace -p <pid> -f -T -r -s 10000):

     0.000277 socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 11 <0.000061>
     0.000129 setsockopt(11, SOL_TCP, TCP_NODELAY, [1], 4) = 0 <0.000045>
     0.000107 fcntl(11, F_GETFL) = 0x2 (flags O_RDWR) <0.000040>
     0.000094 fcntl(11, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000043>
     0.000125 connect(11, {sa_family=AF_INET, sin_port=htons(443),
sin_addr=inet_addr("64.30.224.206")}, 16) = -1 EINPROGRESS (Operation
now in progress) <0.000051>
     0.000140 poll([{fd=11, events=POLLOUT|POLLWRNORM}], 1, 0) = 0
(Timeout) <0.000027>
     0.000083 poll([{fd=11, events=POLLOUT}], 1, 1) = 0 (Timeout) <0.001111>
     0.001228 poll([{fd=11, events=POLLOUT|POLLWRNORM}], 1, 0) = 0
(Timeout) <0.000055>
     0.000141 poll([{fd=11, events=POLLOUT}], 1, 197) = 1 ([{fd=11,
revents=POLLOUT}]) <0.130495>
     0.130676 poll([{fd=11, events=POLLOUT|POLLWRNORM}], 1, 0) = 1
([{fd=11, revents=POLLOUT|POLLWRNORM}]) <0.000062>
     0.000165 getsockopt(11, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 <0.000061>
     0.000147 getpeername(11, {sa_family=AF_INET, sin_port=htons(443),
sin_addr=inet_addr("64.30.224.206")}, [16]) = 0 <0.000056>
     0.000165 getsockname(11, {sa_family=AF_INET, sin_port=htons(44502),
sin_addr=inet_addr("192.168.100.190")}, [16]) = 0 <0.000036>
     0.000124 socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 12 <0.000059>
     0.000195 fcntl(12, F_GETFL) = 0x2 (flags O_RDWR) <0.000044>
     0.000108 fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000032>
     0.000096 getpeername(12, 0x7ffe5203f800, 0x7ffe5203f7d4) = -1
ENOTCONN (Transport endpoint is not connected) <0.000035>
     0.000098 stat("/etc/pki/tls/certs/ca-bundle.crt",
{st_mode=S_IFREG|0444, st_size=253335, ...}) = 0 <0.000059>
     0.000181 open("/etc/pki/tls/certs/ca-bundle.crt", O_RDONLY) = 13
<0.000056>
     0.000137 fstat(13, {st_mode=S_IFREG|0444, st_size=253335, ...}) = 0
<0.000033>
     0.000115 read(13, "-----BEGIN
CERTIFICATE-----\nMIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMC
[...]
             
C5u\nZXQvQ1BTIGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMc"...,
253335) = 253335 <0.000102>
     0.001565 close(13) = 0 <0.000072>
    13.618840 fcntl(11, F_GETFL) = 0x802 (flags
O_RDWR|O_NONBLOCK) <0.000083>
     0.000148 fcntl(11, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000028>
     0.000075 getpeername(11, {sa_family=AF_INET, sin_port=htons(443),
sin_addr=inet_addr("64.30.224.206")}, [16]) = 0 <0.000035>
     0.000141 close(12) = 0 <0.000036>
     0.000103 close(11) = 0 <0.000044>

(hope I'm not missing parts of the strace here)

As you can see, fnctl() takes a lot of time to complete. I'm not skilled
enough to understand what it does, why it does that, and if it's really
inside the cURL call that the problem resides. But the time fnctl()
takes increases at each new iteration.

Any hint ?

Thank you !

    Hoggins!

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Received on 2016-06-21