My app is using curl_multi_select to wait for curl calls to complete. The default timeout in curl_multi_select is set to 1 second. For a given url, this call returns immediately on Linux, but waits for the full 1 second timeout on OSX.
Unfortunately, changing the timeout in the code isn't really an option in my situation - I need a way to change the machine configuration or use different php modules/exes.
Both linux and osx boxes are running PHP 5.3.8. There seems to be something with the way OSX handles sockets and the select() call itself that is different from Linux.
Here's what the curl call does:
'url' => string 'HTTP://172.19.105.171:8070 <SNIPPED> '... (length=1439)
...
'namelookup_time' => float 1.001309
And here's what the select call looks like using dtruss:
sudo dtruss -a -n httpd > dtruss.txt.2 2>&1
PID/THRD RELATIVE ELAPSD CPU SYSCALL(args) = return
...
21524/0x17136: 14369 37 31 connect_nocancel(0xA, 0x7FFF649DB9F8, 0x6A) = 0 0
21524/0x17136: 14383 15 10 sendto_nocancel(0xA, 0x7FAA786E4AD0, 0x1C) = 28 0
20285/0x8d8d: 755608 1001045 16 select(0x0, 0x0, 0x0, 0x0, 0x7FFF64353A70) = 0 0
Notice that the select call is taking 1001045 microsecs, which is 1 second.
So - is this related to the way OSX handles sockets? Is it something I could change with a different build option in PHP/Curl? Or is there something I could change about my network config to make the select() call return faster?
This is the original issue I had before I narrowed it down to the current question:
PHP/curl: namelookup_time/dns slowing requests
Other research:
http://www.somacon.com/p537.php
http://svn.php.net/viewvc/php/php-src/trunk/ext/curl/multi.c?view=markup (curl_multi_select source code)
You can try
usleep(30000); // 0.03s
instead of
curl_multi_select($mh);
You'll probably need to play with amount of microseconds, but I think that 0.03s is enough for basic use.
Also you will have to implement timeouts by yourself. It can be done with writing microtime(true)
to variable and comparing it with current time on every loop call.