3

If you type

nslookup -type=SRV _xmpp-server._tcp.gmail.com

(or use the dig command in OSX) you get some SRV records relating to google chat

I would like to replicate this functionality in PHP, does anyone have any good ideas how to do this?

I would like to avoid using exec() as this does not return 100% standard responses across OSX/*NIX/WINDOWS

Thanks!

adam
  • 22,404
  • 20
  • 87
  • 119

2 Answers2

9

There is dns_get_record(). According to the docs it can take an int $type argument, which refers to a set of constants, one of them being DNS_SRV.

Maciej Łebkowski
  • 3,837
  • 24
  • 32
Tomalak
  • 332,285
  • 67
  • 532
  • 628
8

You could use Pear Net_DNS. I managed to get this to work on Linux, but haven't tested it on Windows or any others:

require_once('Net/DNS.php');
$resolver = new Net_DNS_Resolver();
$response = $resolver->query('_xmpp-server._tcp.gmail.com', 'SRV');
if ($response) {
    foreach ($response->answer as $rr) {
        $rr->display();
    }
}

I modified the example from their documentation. hope this helps

Manoj Sharma
  • 1,467
  • 2
  • 13
  • 20
Tom Haigh
  • 57,217
  • 21
  • 114
  • 142
  • I would rather privilege native PHP function over oldish PEAR libraries that doesn't play well with up-to-date PHP version. Answer of @Tomalak looks much better to me. – Patrick Allaert Jun 16 '16 at 15:46