7

I have install WampServer 2.0 that has apache 2.4.4, mysql 5.6.12, and php 5.4.12. When I echo PHP_INT_MAX it gave me 2147483647. I have also echo phpinfo() and the architecture indicates x64. This suppose to be not happening because my php is 64 bit right? I need my php to support 64 bit integer. I need my PHP_INT_MAX to be 9223372036854775807.

Can somebody help me? Thanks

JJJ
  • 32,902
  • 20
  • 89
  • 102
mikellez
  • 91
  • 1
  • 1
  • 7
  • *`long` must become `long long` in the PHP source. Then recompile! :) - have no idea if it would work as it might break things everywhere.* I hope they eventually go to a 64bit long representation. But there's pretty much nothing you can do about this. I also hope they'll go Unicode... but there's little hope. – CodeAngry Jul 24 '13 at 14:44
  • I'm not 100% right now and too busy to look it up but `floats` in PHP are `doubles` which ARE `64bit` even on Windows, while `floats` are 32bit. So you might try to use them. – CodeAngry Jul 24 '13 at 14:48
  • The problem now is I can't proceed with my code when I execute it because i'm trying to integrate dropbox into my website, when I run my code using dropbox sdk, it has error which state that my version of php doesn't support 64 bit integer, so I can't proceed with the integration. – mikellez Jul 24 '13 at 14:55
  • can you post error message? – Vadim Jul 24 '13 at 14:56
  • Fatal error: Uncaught exception 'Exception' with message 'The Dropbox SDK uses 64-bit integers, but it looks like we're running on a version of PHP that doesn't support 64-bit integers (PHP_INT_MAX=2147483647). Library: "C:\wamp\www\dropbox-sdk\Dropbox\RequestUtil.php"' in C:\wamp\www\dropbox-sdk\Dropbox\RequestUtil.php on line 15 – mikellez Jul 24 '13 at 15:00
  • please, check http://stackoverflow.com/questions/864058/how-to-have-64-bit-integer-on-php seems you can't have 64bit integers on windows – Vadim Jul 24 '13 at 15:15
  • and IMHO, I think it's better to use library, which used string implementation for big numbers – Vadim Jul 24 '13 at 15:18

5 Answers5

10

If you're running a windows OS, wampServer suggests you are, this is your answer:

On windows x86_64, PHP_INT_MAX is 2147483647. This is because in the underlying c-code, a long is 32 bit.

Note that this doesn't mean that Windows doesn't support 64bit int's: int64_t does exist, but it's not used by PHP AFAIK.
I've managed to come up with this link, on that page, there's some code you might be able to use, to add support for 64bit ints to your code

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
  • thanks for the reply. So is there any way to solve this problem? I don't really understand what it is telling me to do with the link you gave me. – mikellez Jul 24 '13 at 14:43
  • @user2615039: [there is a hacky workaround](http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/), that doesn't require you to switch to linux ;) – Elias Van Ootegem Jul 24 '13 at 14:45
4

In the file RequestUtil.php, it does the following check:

if (strlen((string) PHP_INT_MAX) < 19) {
    // Looks like we're running on a 32-bit build of PHP.  This could cause problems because some of the numbers
    // we use (file sizes, quota, etc) can be larger than 32-bit ints can handle.
    throw new \Exception("The Dropbox SDK uses 64-bit integers, but it looks like we're running on a version of PHP that doesn't support 64-bit integers (PHP_INT_MAX=" . ((string) PHP_INT_MAX) . ").  Library: \"" . __FILE__ . "\"");
}

You can comment it out and try hacking your way from there.

If I were you, I'd write my own Dropbox API implementation using strings and not integers.

PS: But this is what I do so I enjoy it :)

CodeAngry
  • 12,760
  • 3
  • 50
  • 57
  • thanks for the alternative solution, just hope it won't cause problems later on. – mikellez Jul 24 '13 at 15:06
  • @user2615039 **It might**, *but you can at least move on with testing.* Always try to treat long integers as string and you might get away with it. – CodeAngry Jul 24 '13 at 15:56
1

Try PHP7 - the current master http://windows.php.net/downloads/snaps/master/ . 64-bit builds now exploit all the capabilities of the 64-bit Windows.

Anatol Belski
  • 660
  • 6
  • 8
  • "PHP 7 provides full 64-bit support. The x64 builds of PHP 7 support native 64-bit integers, LFS, memory_limit and much more." So, all builds, not only master: http://windows.php.net/download/ – Sędziwój Aug 08 '16 at 09:02
  • Yea, 7.0 was master to the time of posting :) After the GA it's now any build OFC. – Anatol Belski Aug 08 '16 at 09:07
1

Go to 'vendor/dropbox/dropbox-sdk/lib/Dropbox'
and comment lines 19-23 in RequestUtil.php.

Comment this section:

/*if (strlen((string) PHP_INT_MAX) < 19) {
    // Looks like we're running on a 32-bit build of PHP.  This could cause problems because some of the numbers
    // we use (file sizes, quota, etc) can be larger than 32-bit ints can handle.
    throw new \Exception("The Dropbox SDK uses 64-bit integers, but it looks like we're running on a version of PHP that doesn't support 64-bit integers (PHP_INT_MAX=" . ((string) PHP_INT_MAX) . ").  Library: \"" . __FILE__ . "\"");
}*/

That's it.

Pang
  • 9,564
  • 146
  • 81
  • 122
-1

I tried php7 and it worked:

running php.exe -r "echo PHP_INT_MAX;"

and it outputs 9223372036854775807

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
Jeff Chen
  • 19
  • 2