flow / email-checker
使用 ReactPHP 著名的非阻塞事件循环,通过 SMTP 在邮件服务器上检查电子邮件地址是否存在
0.3.0
2013-11-06 10:35 UTC
Requires
- react/react: 0.3.*
README
EmailChecker 通过 SMTP 连接到邮件服务器,并要求它们验证电子邮件地址。该库使用 ReactPHP 的事件驱动 IO 层来处理所有套接字通信。
主要功能
- N 个连接可以并发打开并异步处理,这归功于 ReactPHP。
- 连接被池化并保持活跃,以便高效地处理对同一域的多个请求。
注意事项
- SMTP 服务器可能会返回任何旧的随机响应,因此无法信任,尤其是在请求邮箱的 RCPT 时(尽管这种方法比什么都没有好)。
- MX 记录是通过
getmxrr()
解析的,因此该操作是阻塞的。
待办事项
- 当支持 MX 记录解析时,实现
React/DNS
。 - 为所有内容编写单元测试。
示例
use Flow\EmailChecker\ConnectionPool;
use Flow\EmailChecker\MailboxUser;
$loop = React\EventLoop\Factory::create();
$emails = array(
'stephen@flowsa.com',
'i-dont-exist-asdf-1234@gmail.com'
);
$connectionPool = new ConnectionPool($loop, 'flowsa.com', 'stephen', function (ConnectionPool $pool) use (& $emails) {
$email = array_shift($emails);
if (!$email) {
return false; // Returning false will cause the connection pool to drain and eventually die
}
$pool->add(
$email,
function (MailboxUser $email) { // Bind in a closure for the callback that occurs after an email is resolved
echo $email->getEmail() . ($email->exists() ? ' exists' : ' does not exist') . "\n";
}
);
}, function ($str) {
echo "$str\n";
});
$connectionPool->setConcurrency(10);
$connectionPool->run();