Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if your code is running on 64-bit PHP

Tags:

php

Does anyone know of a way of checking within PHP if the script is running as either 32-bit or 64-bit? Currently I'm using PHP 5.3.5.

Ideally I'd like to write a function so my code can look like this:

if( is_32bit() === true ) {     do_32bit_workaround(); } do_everything_else(); 

Anyone have any thoughts?

like image 535
binarycleric Avatar asked Mar 24 '11 18:03

binarycleric


People also ask

How do I check if PHP is 32 bit or 64 bit?

To check if you are running on 64-bit, just look under “Architecture” in phpinfo () – X86 is 32-bit, and X64 is 64-bit. Otherwise, if you want to test it out programmatically, you can check the PHP_INT_SIZE constant.

How do I check if my PHP version is running?

Check PHP Version by Running PHP Code The simplest method to determine the PHP version running on your website is executing a PHP file that contains the following code: <?php echo 'PHP version: '. phpversion (); Create the file using a text editor like gedit or Notepad, and upload it to your website’s document root directory.

Why is PHP-V not working on Windows?

This version is not necessarily the one that runs on the hosted websites. On Windows, the PHP path is sometimes not recognized by the system, so the php -v command outputs the ‘ php is not recognized ’ error. To solve this problem, set the PATH environment variable first.

Do we need these tools to check our PHP code?

Do we really need these tools to check our PHP code? My experience showed me that software entropy is a real thing. More you will modify your application, more the application has chances to break. Your application will inevitably become more complex. These PHP code quality tools can definitely help you in that matter.


1 Answers

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.

like image 95
coreyward Avatar answered Sep 25 '22 12:09

coreyward