dongsha9208 2016-10-02 11:39
浏览 107
已采纳

提高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

  • 写回答

1条回答 默认 最新

  • dpz3471 2016-10-02 12:39
    关注

    $ 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"
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波