Find Windows 32 or 64 bit using PHP

前端 未结 6 1583
清酒与你
清酒与你 2020-12-05 11:05

Is it possible to get the window processor bit?? I want to find the window processor bit using php?? I have coding to find the operating system and other properties. Kindly

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 11:48

    If you have the COM extension installed (in php.ini) you can call the windows WMI service.

    (Remember though that you event if you have a 64-bit processor, 64-bit OS and 64-bit PHP, your integers are still going to be 32-bit due to a limitation in x64-PHP on Windows.)

    Anyway...

    To check the OS:

    function getOsArchitecture() {
        $wmi = new COM('winmgmts:{impersonationLevel=impersonate}//./root/cimv2');
        $wmi = $obj->ExecQuery('SELECT * FROM Win32_OperatingSystem');
        if (!is_object($wmi)) {
            throw new Exception('No access to WMI. Please enable DCOM in php.ini and allow the current user to access the WMI DCOM object.');
        }
        foreach($wmi as $os) {
            return $os->OSArchitecture;
        }
        return "Unknown";
    }
    

    or, check the physical processor:

    function getProcessorArchitecture() {
        $wmi = new COM('winmgmts:{impersonationLevel=impersonate}//./root/cimv2');
    
        if (!is_object($wmi)) {
            throw new Exception('No access to WMI. Please enable DCOM in php.ini and allow the current user to access the WMI DCOM object.');
        }
        foreach($wmi->ExecQuery("SELECT Architecture FROM Win32_Processor") as $cpu) {
            # only need to check the first one (if there is more than one cpu at all)
            switch($cpu->Architecture) {
                case 0:
                    return "x86";
                case 1:
                    return "MIPS";
                case 2:
                    return "Alpha";
                case 3:
                    return "PowerPC";
                case 6:
                    return "Itanium-based system";
                case 9:
                    return "x64";
            }
        }
        return "Unknown";
    }
    

提交回复
热议问题