如何防止curl_multi_select挂在osx上? [英] How can I prevent curl_multi_select from hanging on osx?

查看:236
本文介绍了如何防止curl_multi_select挂在osx上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式正在使用curl_multi_select等待curl调用完成。 curl_multi_select中的默认超时设置为1秒。对于给定的url,此调用在Linux上立即返回,但在OSX上等待完整的1秒超时。



不幸的是,改变代码中的超时不是真的在我的情况下一个选项 - 我需要一种方法来改变机器配置或使用不同的php模块/ exes。



linux和osx框都运行PHP 5.3.8。似乎有一些方式OSX处理套接字和select()调用本身不同于Linux。



curl调用:

 'url'=> string'HTTP://172.19.105.171:8070< SNIPPED> '...(length = 1439)
...
'namelookup_time'=> float 1.001309

这里是select调用看起来像使用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

请注意,select调用需要1001045微秒, >

所以 - 这是与OSX处理套接字的方式有关吗?这是我可以改变与PHP / Curl中不同的构建选项的东西吗?或者有什么东西我可以改变我的网络配置让select()调用返回更快?



这是我之前我把它缩小到当前问题:

PHP / curl:namelookup_time / dns slowing请求



其他研究:

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)

解决方案

您可以尝试

  usleep(30000); // 0.03s 

而不是

  curl_multi_select($ mh); 

你可能需要玩微秒数,但我认为0.03s就足够了基本使用。



此外,您还需要自己实现超时。
可以通过写 microtime(true)到变量并将其与每个循环调用的当前时间进行比较。


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.

这篇关于如何防止curl_multi_select挂在osx上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆