tags:

views:

903

answers:

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!

+8  A: 

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

Tom Haigh
+5  A: 

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.

EDIT: According to the same docs:

Note: This function is not implemented on Windows platforms, nor does it (currently) work on *BSD systems (including Mac). Try the » PEAR class » Net_DNS.

Tomalak
A: 

Thankyou both, however the dns_get_record man page tells me the following

Note: This function is not implemented on Windows platforms, nor does it (currently) work on *BSD systems (including Mac). Try the » PEAR class » Net_DNS.

So tomhaigh, you win; but Tomalok you come in a close second :p

adam
"This function is not implemented on Windows platforms"... Feh. :-)
Tomalak