提高exec()语句的性能

提高exec()语句的性能

问题描述:

I have an issue, that is not necessarily in the scope of most questions asked here.

I have an application I am developing that checks a domain for certain A records and also tests ports on the resolving server to check if they are open and listening.

I have added functionality on my local copy of the site, but it is too slow for me to publish, come to think of it, so is the current published site.

You can see the app on the link: http://www.domainion.co.za

Enter a domain name (without www) and it will check for certain records.

This is a symfony app, I am getting these records by running multiple exec() statements with digs for specific information. The reason I like using exec, is because if there are multiple records returned, like the below command, it lets you assign each result to an index of an array.

dig -x 154.0.174.35 +short @8.8.8.8

motairgdiool.hosted.co.za. (index 0)

kent.aserv.co.za. (index 1)

Now, this is taking way too long (on average 8 seconds to load). My issue with this, is if you had to take all these commands in this app and run it in a shell script, they take under a second to run, I suspect the reason mine takes so long, is that PHP is opening and closing a virtual shell for each of these commands.

In an attempt to run these queries quicker, I have tried the below:

shell_exec() - This takes about the same time, and returns all results as a string, I can't use that.

proc_open - takes longer, also returns a long string.

symfony process() component - takes waaay longer and also returns all results as one string

dns_check_record() - you can't check for specific subdomain records

TLDR : Is there any way I can get records that i want (n.domain.tld) and still have the application run fast?

Thanks

我有一个问题,这不一定在这里提出的大多数问题的范围内。 p>

我有一个我正在开发的应用程序,它检查某个域的某些A记录,还测试解析服务器上的端口,检查它们是否处于打开和监听状态。 p>

我有 在我的本地网站副本上添加了功能,但对我来说发布太慢了,想到它,当前发布的网站也是如此。 p>

你可以看到应用程序 链接: http://www.domainion.co.za p> 输入一个域名(没有www),它将检查某些记录。 p>

这是一个symfony应用程序,我通过使用digs运行多个exec()语句来获取这些记录 具体信息。 我喜欢使用exec的原因是因为如果返回了多个记录,就像下面的命令一样,它允许你将每个结果分配给一个数组的索引。 p>

dig -x 154.0。 174.35 +短@8.8.8.8 p>

motairgdiool.hosted.co.za。 (索引0) p>

kent.aserv.co.za。 (索引1) p>

现在,这花费的时间过长(平均加载时间为8秒)。 我的问题是,如果你不得不在这个应用程序中使用所有这些命令并在shell脚本中运行它们,它们需要一秒钟才能运行,我怀疑我需要这么长时间的原因,就是PHP正在打开和关闭一个 每个命令的虚拟shell。 p>

为了更快地运行这些查询,我尝试了以下方法: p>

shell_exec( ) strong> - 大约需要相同的时间,并将所有结果作为字符串返回,我无法使用它。 p>

proc_open strong> - 需要更长的时间 ,也返回一个长字符串。 p>

symfony process()组件 strong> - 花费更长时间并将所有结果作为一个字符串返回 p>

dns_check_record() strong> - 您无法检查特定的子域记录 p>

TLDR:有什么方法可以获得我想要的记录( n em> .domain.tld)并且仍然可以快速运行应用程序? p>

谢谢 p> div>

$ php -r 'var_dump(dns_get_record("35.174.0.154.in-addr.arpa"));'

Returns the following in under a one fifth of a second, including invoking the PHP interpreter:

array(2) {
  [0]=>
  array(5) {
    ["host"]=>
    string(25) "35.174.0.154.in-addr.arpa"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(7192)
    ["type"]=>
    string(3) "PTR"
    ["target"]=>
    string(16) "kent.aserv.co.za"
  }
  [1]=>
  array(5) {
    ["host"]=>
    string(25) "35.174.0.154.in-addr.arpa"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(7192)
    ["type"]=>
    string(3) "PTR"
    ["target"]=>
    string(25) "motairgdiool.hosted.co.za"
  }
}