从 mysql 发送终端/shell 命令到终端并在循环光标时检索答案
我在 macOS 上使用 php 和 MySQL。 我想从数据库中选择大量电子邮件,并使用终端/shell 中的 dig 命令对我选择的每封电子邮件执行 dns 查找,例如: "dig gmail.com" 。 当然,我可以通过 php 循环这个选择,但与 MySQL 上的循环游标相比,它会非常慢。 如何在 macOS 上将终端命令从 mysql 发送到终端并检索答案?
I'm using php with MySQL on macOS.
I would like to select a large amount of emails from a database and perform a dns lookup for each email in my selection using a dig command from the terminal/shell, something like: "dig gmail.com" .
Of course, I can loop this select through php but it will be very slow compared to looping cursor on MySQL.
How to send terminal commands from mysql to the terminal and retrieve answer on macOS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能从 SQL 查询中执行 shell 命令(感谢上帝),否则这将是一个可怕的安全漏洞......你必须从 php 执行它。
PS 然而,可以从 MySQL 命令行实用程序执行 shell 命令
...但如果我理解你的问题,它无助于解决你当前的问题。
You can't execute shell commands from within an SQL query (thank god), or else it would be a horrible security vulnerability... You would have to do it from php.
P.S. It is however possible to execute shell commands from the MySQL command line utility
...but if I understand your question, it won't help solve your current problem.
(我假设当您谈论电子邮件地址时,您真正指的是 ADDR_SPEC)
不,不是真的。唯一的区别是,根据您的实现方式,PHP 方法要求您在开始迭代之前检索整个结果集。然而,将其分解为更小的结果集是微不足道的。
此外,算法性能的限制是 DNS 查找的速度 - 这就是延迟 - 如果您的目标是使其速度更快,那么您应该并行运行多个请求。
接下来您应该考虑的是,每个 MX 可能有多个邮箱,例如 [电子邮件受保护],[电子邮件受保护]....如果您已正确设置 DNS 缓存如果您正在处理非常大的数据集或将不止一次执行此操作,使用唯一的 MX 主机值更有意义,例如,
确实,如果您标记数据,那么您可以使用自己的数据库来验证 MX。
请不要告诉我您正在从 PHP 控制进程运行 shell 来执行 DNS 查找?
(I'm assuming that you really mean ADDR_SPEC when you're talking about email addresses)
No not really. The only difference is that depending on how you implement this the PHP approach requires that you retrieve the entire result set before you start iterating through it. However breaking this up into smaller result sets is trivial.
Also, the limitation on the performance of your algorithm is the speed of DNS lookups - and that's all about latency - if your objective is to make this go faster then you should be running multple requests in parallel.
The next thing you should consider is that you've probably got multiple mailboxes for each MX, e.g. [email protected], [email protected].... While if you've got DNS caching setup properly there will be less overhead than going to the source each time, if you're working with a very large data set or will be doing this more than once, it makes a lot more sense to just work with unique MX host values, e.g.
Indeed, if your flagging the data then you can use your own database to verify the MX.
Please don't tell me that you're running a shell from a PHP controlling process to do a DNS lookup?