Page 1 of 1

Different results for same code in different PHP version???

Posted: Tue Jan 16, 2007 5:45 pm
by larttaus
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,

I have the following code from a google page rank script checker, but I get different results depending upon which version of PHP I use. Why would there be a difference? Is it because of the PHP version? or what OS apache is sitting on? Has something altered in PHP that affects the way these functions  are calculated? - as two run on the same host just different php versions.

I have one version which works correctly, this is installed on my XP home box running apache 4.2.3 (phpdev)
I have another version which fails on my internet hosts server (RedHat) with apache 4.4.4
Another version which fails on my internet hosts server (RedHat) with apache 5.1.6
Lastly another working copy on my XP Home box running apache 5.2.0 (xampp)

The code that fails/changes is below:

Code: Select all

function zeroFill($a, $b)
{
	echo "zeroFill: " . $a . " " . $b . "<br/>";
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>1);
            $a &= (~$z);
            $a |= 0x40000000;
            $a = ($a>>($b-1));
            echo "zeroFill: za<br/>";
        }
        else
        {
            $a = ($a>>$b);
            echo "zeroFill: a<br/>";
        }
        echo "zeroFill: " . $a . "<br/>";
        return $a;
}


function mix($a,$b,$c) {
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
	echo $a . " $a<br/>"; // response up to here posted below
  $b -= $c; $b -= $a; $b ^= ($a<<8);
	echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
	echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
	echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<16);
	echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
	echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
	echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<10);
	echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
	echo $c . " $c<br/>";

  return array($a,$b,$c);
}
To make things short I've only pasted part of the response (the first processed line from the mix function):

Apache Version: 4.2.3 / 5.2.0 (Working)

Code: Select all

zeroFill: 1520109454 13
zeroFill: a
zeroFill: 185560
-1655620743 -1655620743
Apache Version: 4.4.4 (Fails)

Code: Select all

zeroFill: 5815076750 13
zeroFill: za
zeroFill: 524287
-2146959361 -2146959361
Apache Version: 5.1.6(Fails)

Code: Select all

zeroFill: 5815076750 13
zeroFill: a
zeroFill: 185560
-2147298088 -2147298088
Any help or comments would be much appreciated, from this quick test I'd say the OS affects the results, can I find anywhere I can download 4.4.4 or 5.1.6 to test on my XP box?

Kind Regards

Matthew


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Jan 16, 2007 6:06 pm
by volka
What code did you use to test the two functions?

Posted: Tue Jan 16, 2007 11:33 pm
by larttaus
(Thanks feyd for pointing me in the right direction - I shall post like that from now on)

Hi Volka,

The script I am using is accessible from here as a text file:

http://ccgi.larttaus.plus.com/testfile.txt

Which is another server (linux) running 4.3.10 and still fails.

Or the code:

Code: Select all

<?php
define('GOOGLE_MAGIC', 0xE6359A60);

function zeroFill($a, $b)
{
	echo "zeroFill: " . $a . " " . $b . "<br/>";
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>1);
            $a &= (~$z);
            $a |= 0x40000000;
            $a = ($a>>($b-1));
            echo "zeroFill: za<br/>";
        }
        else
        {
            $a = ($a>>$b);
            echo "zeroFill: a<br/>";
        }
        echo "zeroFill: " . $a . "<br/>";
        return $a;
}


function mix($a,$b,$c) {
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
	echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<8);
	echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
	echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
	echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<16);
	echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
	echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
	echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<10);
	echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
	echo $c . " $c<br/>";

  return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
    if(is_null($length)) {
        $length = sizeof($url);
    }
    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;
    while($len >= 12) {
        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));	

        $mix = mix($a,$b,$c);
        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
        $k += 12;
        $len -= 12;
    }
		echo $a . " $a<br/>";
		echo $b . " $b<br/>";
		echo $c . " $c<br/>";

		echo $mix . " $mix<br/>";
		echo $k . " $k<br/>";
    $c += $length;
    switch($len)
    {
        case 11: $c+=($url[$k+10]<<24);
        case 10: $c+=($url[$k+9]<<16);
        case 9 : $c+=($url[$k+8]<<8);
        case 8 : $b+=($url[$k+7]<<24);
        case 7 : $b+=($url[$k+6]<<16);
        case 6 : $b+=($url[$k+5]<<8);
        case 5 : $b+=($url[$k+4]);
        case 4 : $a+=($url[$k+3]<<24);
        case 3 : $a+=($url[$k+2]<<16);
        case 2 : $a+=($url[$k+1]<<8);
        case 1 : $a+=($url[$k+0]);
    }
    $mix = mix($a,$b,$c);
    return $mix[2];
}

function strord($string) {
    for($i=0;$i<strlen($string);$i++) {
        $result[$i] = ord($string{$i});
    }
    return $result;
}

function getrank($url)
{
if (isset($_GET['url']) && !empty($_GET['url'])){
$url = 	'info:'. $_GET['url'];
}
$ch = GoogleCH(strord($url));


}

if (isset($_GET['url']) && !empty($_GET['url'])){
    $url = $_GET['url'];
    $pr = getrank($url);

	}

?>
All versions I have tested work up until the first call to the mix() function in the function GoogleCH() which is where they start to deviate.

Kind Regards

Matthew