1

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);
Machavity
  • 30,841
  • 27
  • 92
  • 100
shad
  • 341
  • 1
  • 2
  • 8
  • What errors do you get, when you remove the `@` suppressor? – Peon Jan 02 '14 at 12:12
  • No errors at all. That's the problem. – shad Jan 02 '14 at 12:22
  • `self::TIMEOUT_CONNECTION` Have you tried changing that value in `php.ini default_socket_timeout` too? – Peon Jan 02 '14 at 12:27
  • Still no luck.. `ini_get("default_socket_timeout"): 0.05` `Stream socket: 5.0396149158478` – shad Jan 02 '14 at 12:37
  • Then are you really sure that the problem is not somewhere else? I suggest you debug line by line or check if the timeout does not get overwritten somewhere else. – Peon Jan 02 '14 at 12:39
  • I'm not sure, but i don't know where to look anymore. I've even put `ini_set('default_socket_timeout', 0.05)` right before `stream_socket_client`. `self::TIMEOUT_CONNECTION` also equals 0.05 right before socket opening.. – shad Jan 02 '14 at 12:40
  • Did you find a solution to this problem meanwhile? – Armin Hierstetter Jul 14 '16 at 20:09

0 Answers0