PHP stream_socket_client ignoring timeout

自古美人都是妖i 提交于 2019-12-11 05:38:09

问题


I'm using zend_mail from zend-framework2 in my project to send some amount of emails in a loop, but sometimes it takes more than usual to send an email. After doing some research, i found that the delay occurs on the stream_socket_client function. I tried to set this function's timeout to acceptable value, but it seems to ignore that setting. Also tried to use STREAM_CLIENT_PERSISTENT to limit the number of opened sockets but with no luck.

Average stream_socket_client times are about 0.03 seconds and occasionally it takes from 5 seconds up to even 40 seconds. Every value above 0.5 seconds is unacceptable for me. I'm out of ideas what can cause that issue.

Current setup:

$start = microtime(true);  

$this->socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT);

echo 'Stream socket: '.(microtime(true) -  $start);

来源:https://stackoverflow.com/questions/20882654/php-stream-socket-client-ignoring-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!