larttaus Posted January 16, 2007 Share Posted January 16, 2007 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.4Another version which fails on my internet hosts server (RedHat) with apache 5.1.6Lastly another working copy on my XP Home box running apache 5.2.0 (xampp)The code that fails/changes is below:[code]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);}[/code]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]zeroFill: 1520109454 13zeroFill: azeroFill: 185560-1655620743 -1655620743[/code]Apache Version: 4.4.4 (Fails)[code]zeroFill: 5815076750 13zeroFill: zazeroFill: 524287-2146959361 -2146959361[/code]Apache Version: 5.1.6(Fails)[code]zeroFill: 5815076750 13zeroFill: azeroFill: 185560-2147298088 -2147298088[/code]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 RegardsMatthew Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/ Share on other sites More sharing options...
HuggieBear Posted January 16, 2007 Share Posted January 16, 2007 [quote author=larttaus link=topic=122721.msg506510#msg506510 date=1168990844]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?[/quote]Give this a try...http://museum.php.net/RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162442 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 Thanks for the link, unfortunately just my luck the highest revisions they go up to is 4.4.2 and 5.1.4 - just below the ones I'd like to test!I shall try those two however on my PC however.CheersMatthew Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162586 Share on other sites More sharing options...
kenrbnsn Posted January 17, 2007 Share Posted January 17, 2007 Please post the script that calls these functions.Ken Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162591 Share on other sites More sharing options...
btherl Posted January 17, 2007 Share Posted January 17, 2007 My results for versions 4.4.2, 5.1.4 and 5.2.0 on linux match your "working" output.Are you assuming 32-bit or 64-bit integer size in any of that code? Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162605 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 The code is: (also available as txt file: [url=http://ccgi.larttaus.plus.com/testfile.txt]http://ccgi.larttaus.plus.com/testfile.txt[/url][code]<?phpdefine('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); }?>[/code]RegardsMatthew Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162622 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 [quote author=btherl link=topic=122721.msg506684#msg506684 date=1169012652]My results for versions 4.4.2, 5.1.4 and 5.2.0 on linux match your "working" output.Are you assuming 32-bit or 64-bit integer size in any of that code?[/quote]The honest reply would be not sure.... I am not too strong a PHP programmer... Matthew Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162626 Share on other sites More sharing options...
btherl Posted January 17, 2007 Share Posted January 17, 2007 Hmm.. well it "looks" like it depends on 32 bit integers. A 64 bit OS could easily break it. Can you find out from your hosting provider whether they run a 32 bit or 64 bit version of Red Hat?If they do, then that's very likely the cause. If not, then back to square one. Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162636 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 I have asked my hosting providers whether they use 32 or 64 bit servers, but for the time being all I can provide is:Dual Intel® Xeon Core Processor 3.6GHz with 2MB Cache4 GB SDRAM Redhat Enterprise LinuxWhen I get a response I'll post hereCheers Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162680 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 Just received a response from my hosts, they use 32bit servers.Matt Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162688 Share on other sites More sharing options...
btherl Posted January 17, 2007 Share Posted January 17, 2007 I did some more testing with the full code, and it gives totally different results on a 64 bit system. However it gives the same results on each of the different php versions I tried (4.3.10 & 5.1.4 on 32 bit system, 4.4.2, 5.1.4 and 5.2.0 on 64 bit).The output I got on 64 bit systems was very large (like -8324662986662860468 instead of -781188683), so I'm pretty sure you have 32 bit ints on both your machine and the redhat servers.So that just leaves the different OS.. I would believe that it gives different results on a different OS. Maybe something in the code depends on a particular feature of that OS, or of PHP compiled on that OS.Hmm.. it looks like it implements an encryption algorithm. One solution may be to use a library to do the encryption rather than doing it in php. That would be practical if you can find out what algorithm it is and what inputs it needs. The mcrypt module might be able to help there.Do you know what encryption algorithm it is?One more question :) What did you set url to when you got the output in your first post? And where is that output from? The first thing it printed out? Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162698 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 I have moved the scripts to an accessible part of my website for the time being:PHP5:http://www.web-pages-directory.com/prcheck.php5?url=www.metrodata.co.ukPHP4:http://www.web-pages-directory.com/prcheck.php?url=www.metrodata.co.ukThe url in question tested was: www.metrodata.co.ukUnfortunately I have no idea what the encryption algorithm is sorry Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-162717 Share on other sites More sharing options...
larttaus Posted January 17, 2007 Author Share Posted January 17, 2007 This thread may help, its about the algorithm but not in PHP, though it has a link to a PHP copy that I have tried.http://www.mobileread.com/forums/showthread.php?t=1670Don't know if its of any help..Matthew Quote Link to comment https://forums.phpfreaks.com/topic/34486-different-results-for-same-code-in-different-php-version-help/#findComment-163092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.