Checking If Your Code Is Running on 64-Bit PHP

Checking if your code is running on 64-bit PHP

Check the PHP_INT_SIZE constant. It'll vary based on the size of the register (i.e. 32-bit vs 64-bit).

In 32-bit systems PHP_INT_SIZE should be 4, for 64-bit it should be 8.

See http://php.net/manual/language.types.integer.php for more details.

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

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)...

Find Windows 32 or 64 bit using PHP

<?php
switch(PHP_INT_SIZE) {
case 4:
echo '32-bit version of PHP';
break;
case 8:
echo '64-bit version of PHP';
break;
default:
echo 'PHP_INT_SIZE is ' . PHP_INT_SIZE;
}

This code snippet will at-least tell you if a 32/64 bit version of PHP is running.

How can I determine whether my OS is 32 or 64 bit?

My best guess is that even though your OS is 64bit, your Webserver is x86 and runs in WOW64-mode (32bit). If that's the case, it should be hard to figure out in pure PHP.

My suggestion (thanks to Leigh for linking to a similar question) is to use WMI:

$out = array();
exec("wmic cpu get DataWidth", $out);
$bits = strstr(implode("", $out), "64") ? 64 : 32;
echo $bits; // 32 or 64

How to find out if a shared hosting is running 32 or 64 bit - with php

Do a simple test:

var_dump(is_int( 9223372036854775807 ));

For 32-bit environment it will return false as this number is much bigger that maximum 32-bit integer. For 64-bit environment it will return true.


Or use PHP_INT_MAX as mario suggested in comments.

echo (PHP_INT_MAX == 2147483647)?'32-bit':'64-bit';

Or use PHP_INT_SIZE:

echo (PHP_INT_SIZE * 8) . '-bit';

windows php 64 bit systems ATM

Their API.php contains the following code:

// Detect 64 bit
if (PHP_INT_SIZE < 8) {
throw new Exception('MadelineProto supports only 64 bit systems ATM');
}

What they're doing is not check whenever or not you're running a 64-bit build of PHP or if if your system is 64 bit but rather what the size in bytes for an integer is. That value can be either 4 (32 bit) or 8 (64 bit) on PHP7 (current Windows builds). In older versions of PHP (at least in the 64 bit builds for 5.6, which are marked experimental) that value is going to be always 4.

So in order to use that library on your system you would need to:

  • Upgrade your PHP version to 7

    • The current Windows builds can be found here, you could try to just replace your current PHP installation or look for an updated package of your ... package.

How can I have a 64-bit integer in PHP?

Native 64-bit integers require 64-bit hardware AND the 64-bit version of PHP.

On 32-bit hardware:

$ php -r 'echo PHP_INT_MAX;'
2147483647

On 64-bit hardware:

$ php -r 'echo PHP_INT_MAX;'
9223372036854775807

Numeric problems in PHP (max possible value for a 64 unsigned integer)

Integer in PHP is a signed integer. There are constants PHP_INT_MIN and PHP_INT_MAX for the smallest and largest value.

//64 Bit PHP Version !
var_dump(PHP_INT_MAX); //int(9223372036854775807) = 2**63-1

If the values ​​are greater than the integer range, PHP automatically converts to float. Float, however, is far less precise than 63 bits. This is where the inaccuracies come from.

The bcmath functions can be used to calculate with almost any precision. This code is for checking a number that will come as a string and is an unsigned 64 bit integer.

$val = "18446744073709551614";

$maxUnsign64Bit ="18446744073709551615";
if(ctype_digit($val) AND bccomp($val,$maxUnsign64Bit) !== 1){
echo 'is a 64 Bit number';
};

Can 32-Bit PHP run a .vbs script on a 64-Bit IIS Server?

It's a bit messy. PHP calls WScript.Shell.Run which will call cmd (with /c - i.e terminate cmd.exe when it's done its thing) which will call cscript.exe to run and interpret a .vbs. As you can see quite a few things that have to go right! :)

What if you 'wait' for the WScript.Shell.Run call to end (your $wait variable) before continuing execution of the wsh script which will in turn allow PHP to continue execution etc?

Since you're not waiting for the call to finish, PHP thinks its all good and continues onto the next line (interpreted language).

Also, maybe have the .vbs create an empty text file? Just so you have an indication that it has actually run.

Just take a step back, have a beer and it'll come to you! Gogo troubleshoot!

And - http://ss64.com/vb/run.html

If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.



Related Topics



Leave a reply



Submit