tags:

views:

120

answers:

3

My normal development platform for PHP is Linux. I use a Red hat server for my website, my company uses red hat and Fedora for production, and I have Ubuntu at home. I couldn't be happier. Unfortunately, I'm now required to spend a good deal of time working in PHP in Windows using WAMP.

I say this is unfortunate because I am continually finding things which Linux supports which Windows does not. Last year, it actually delayed a project when we realized that WAMP used an earlier version of PHP (this has been fixed by the port of 5.3 to Windows). Today, I just learned that checkdnsrr is not ported to Windows, and the entire pcntl library is unavailable.

So, my questions is this: Is there anywhere which tells me the current differences between Windows and Linux regarding PHP?

I'm not looking for idiosyncrasies, such as those found in the comments here (though those would be nice), but rather which functions will not be available under Windows which are available under Linux.

----------------------- EDIT -------------------------

There have been two comments/statments which say thatcheckdnsrr exists in 5.3 under Windows. Technically, this is correct. PHP will not say that the function does not exist. I don't know if this is the case with all installs or just WAMP, but while yes, it may say that it works, the function does not work as it does in Linux.

--------------------- UPDATE ----------------------

It does not look like there is a good answer possible to this question, but I have found a workaround thanks to one of the suggestions below:

Place this on the production environment. REMEMBER TO FORCE SOME FORM OF SECURITY ON THIS.

 <?php print_r( get_defined_functions() ); ?>

Then run this on the dev environment. it will output all of the functions which are exclusive to the local environment.

$root = file_get_contents( "<path to server>/available.php" );
$root = preg_replace( "/\[[0-9]{1,4}\]\s=>\s/", ( '' ), $root );
$tmp  = '"internal" => array';
$root = explode( "\n", substr( $root, strpos( $root, $tmp ) + strlen( $tmp ) + 1 ) );
array_shift( $root );
array_shift( $root );
$internal = get_defined_functions();
$internal = $internal[ "internal" ];

function trim_array( array $root )
{
    $nroot = array();
    foreach( $root as $key=>$value )
    {
          $value = trim( $value );
          if( !preg_match( "/^[a-zA-Z_]*[aeiouy]+[a-zA-Z0-9_]*$/", $value ) && 
              !preg_match( "/^[a-zA-Z_]*(md5|crc|n12|str|sqrt|ch[a-z]?r|dl|tnt|ftp|png)[a-zA-Z_]*$/", $value ) )
          {
                //echo "\n $key ";
          }
          else
          {
             $nroot[] = $value;
          }
    }

    return $nroot;
}

$root     = trim_array( $root );
$internal = trim_array( $internal );

$diff = array_values( array_diff( $root, $internal ) );
foreach( $diff as $key => $fname )
{
      if( in_array( $fname, $root ) )
      {
            echo "[$key] => $fname <= foreign server only";
      }
      else
      {
            echo "[$key] => $fname <= local";      
      }
      echo "\n";
}
+3  A: 

First, bear in mind that some cross-platform issues are not due to lack of support but the idiosyncrasies you mention, the worst that comes to my mind is the direction of the directory slash. Or the issue is not with the platform but with the server. For instance, Apache has environmental variables that IIS doesn't even though it would seem like things at the HTTP level and TCP/IP level would be OS-neutral.

On that note:

  • pcntl is based on the Unix process model, so it wouldn't have Windows support.
  • checkdnsrr is supported for Windows as of 5.3, and a package existed for adding that extension in Windows before.
  • There is a list on PHP.net of Windows-only extensions (COM being the one that leaps my mind without checking), but my guess is that since PHP was designed originally for Unix (or at least POSIX) and since 85% of the web is on Apache (I made that number up), their isn't as much of an outcry, though you're right that there should be one.

If it was me, I would go crazy and make a script that scraped the entire extension list page and systematically have it check the intro page for "Windows" to get an idea of which ones are either special or not available. But that's me, I'm zany.

Oh,and here's a quick list of libraries that PHP is either developing for Windows or is never going to develop:

http://wiki.php.net/internals/windows/libs

Anthony
I suppose, if you look at the solution posted above, that is more or less what I did. I just combined Gordon's reply with that idea.
Christopher W. Allen-Poole
A: 

For each function, call function_exists, e.g.

function check_function(function_name)
{
    function_exists(function_name) or die(function_name . " missing");
}

check_function("checkdnserr");
James McLeod
And do this for every single function? That is not terribly elegant. Also, calling die() would mean that if the function does not exist (and it is among a series of functions which do not exist), then there would be no feedback on all of other functions.
Christopher W. Allen-Poole
Agreed, on both counts; this is a simplistic example of how to handle the problem. On the other hand, I suspect that there is only a small subset of functions which are problematic, so one need not do this for all functions one calls (although if that is necessary, one could without much trouble create a utility which will parse the PHP and automatically create a new script which calls funcion_exist for each function called. In practice, I have found the approach above to work, although my PHP scripts are not usually very demanding.
James McLeod
+1  A: 

I have no idea if a site like you ask for exists, but you can use these methods to find out about a PHP installation:

It's somewhat difficult to say: this is available on Windows and this isn't on a general basis for often functions depend on the PHP version and this can just as much affect any OS.

Gordon
Does `get_loaded_extensions` return the same thing as phpinfo(), or does it cover core extensions that don't require changes to the config file?
Anthony
While this does not *technically* answer the question, it has the closest thing possible.
Christopher W. Allen-Poole