Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

windows - Can PHP tell if the server os is 64-bit?

I am dealing with Windows here.

I know you can use the $_SERVER['HTTP_USER_AGENT'] variable to detect the OS of the browser viewing the page, but is the any way that PHP can detect the server's OS?

For my program's UI I am using a PHP webpage. I need to read a key in the registry that is in a different location on a 64-bit OS (It is under the Wow6432Node Key).

Can PHP tell what OS it is running on? Can PHP tell if the OS is 64-bit or 32-bit?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Note: This solution is a bit less convenient and slower than @Salman A's answer. I would advice you to use his solution and check for PHP_INT_SIZE == 8 to see if you're on a 64bit os.

If you just want to answer the 32bit/64bit question, a sneaky little function like this would do the trick (taking advantage of the intval function's way of handling ints based on 32/64 bit.)

<?php
function is_64bit()
{
    $int = "9223372036854775807";
    $int = intval($int);
    if ($int == 9223372036854775807) {
        /* 64bit */
        return true;
    } elseif ($int == 2147483647) {
        /* 32bit */
        return false;
    } else {
        /* error */
        return "error";
    }
}
?>

You can see the code in action here: http://ideone.com/JWKIf

Note: If the OS is 64bit but running a 32 bit version of php, the function will return false (32 bit)...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...