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

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?