PHP getmxrr() support for windows

As many of you may be aware there’s a lack of getmxrr() support in Windows, which dates back as far as 1999.

It’s not a major problem for me as an individual because I never use WIN32 PHP in production, but for development and for the purpose of wide distribution it can raise an issue.

Apparently the lack of support in win32 is due to the lack of “res_search” in “bindlib_w32″, I’m surprised this hasn’t been fixed already.

The official PHP.net documentation for the getmxrr() function states:

Note: This function is not implemented on Windows platforms. Try the » PEAR class » Net_DNS.

However, there are problems with this suggestion…

  1. Some users don’t have access to install the required PEAR module.
  2. pear/Net_DNS requires PHP extension “mhash” – some users may not have this installed.
  3. The Net_DNS class does not have a direct equivalent to getmxrr() so results may not be as expected.
  4. It’s not a portable solution, especially if some users experience the above issues.

This isn’t going to be a realistic option for many users.

So, what are the alternatives? Do they have any issues?

  1. Use exec() in conjunction with “nslookup.exe“.
    • When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.
    • “nslookup.exe” may not exist on the system.
    • PHP may not have permission to run “nslookup.exe”.
  2. Write your own class/function to fsockopen() via UDP to a name server and parse the returned information.
    • Long and overly complex.
    • Requires understanding of the DNS related RFCs.
    • Reinventing the wheel, as Net_DNS already handles this.
    • Results may not be as expected.
  3. Fix the implementation problem in PHP core.
    • Not very simple to implement.
    • May be a complex issue.
    • Not backwards compatible.

I think the obvious option here is to run with the first option of using “nslookup” and hope for the best.

With any luck you will find the “getmxrr() support for Windows” function in on the getmxrr() manual page (find the latest here).

NEWS FLASH!

As I write this, and go over the article again, check my links, I see an update on the PHP Bug #5311 tracker:

As a new year present, all DNS functions are now available on windows,
5.3 and 6 (head).

This is good news, all that remains is for PHP_Compat to catch up and use the above suggestions :)

Good luck.

Update: I am now helping the PHP_Compat team. View the getmxrr() support for windows feature request.

Update2: I have now decided to support checkdnsrr() as well. Download checkdnsrr() support for windows.

Update3: I have now decided to support dns_get_record() as well. Coming soon.

Related posts:

  1. Cex.co.uk site errors After browsing the cex.co.uk website for some time I came...
  2. Windows Genuine Advantage Removal First of all for those that don’t know, Windows Genuine...
  3. PHP coding standards and best practices I have been using PHP for a long time now,...
  4. Adding fonts into photoshop without adding them to windows If you use Photoshop for any kind of graphic or...

2 Comments »

  1. Pierre said,

    January 6, 2009 @ 10:43 pm

    hi!

    By the way, bindlib is not used anymore in php’s windows port (5.3 and later).

  2. hm2k said,

    January 8, 2009 @ 12:32 am

    …and it only took just under a decade. :)

RSS feed for comments on this post · TrackBack URL

Leave a Comment