Comments (9)
I thought PHP7 on Windows had 64bit integers?
was does the following result in for you on this configuration:
<?php
$array = ['$set' => ["TestInt" => 4294967295]];
var_dump($array);
?>
from mongo-php-driver.
PHP7 on Windows does have 64bit integers. The snippet above results in
array(1) { ["$set"]=> array(1) { ["TestInt"]=> int(4294967295) } }
The loss of precision happens when interacting with the Mongo driver, in that it treats every number as Int32.
$inc
suffers from the same problem as $set
. That is, if I try to [$inc => ["TestInt" => 4294967295]]
I will actually subtract 1 from TestInt. Further testing has revealed that queries suffer from the same problem: If I were to make a query with a filter like "TestInt" => ['$lt' => 4294967295]
, I'll actually be looking for documents where TestInt is less than -1.
Edit: I'm actually using MongoDB driver 1.1.2, now, but it exhibits the same behaviour.
from mongo-php-driver.
It seems that I lied when I proclaimed that reading an Int64 from the db is fine. It turns out that it comes back as a string and is liable to have its property name mangled.
With the following test document
{
"_id" : ObjectId("569d015eb26caf586174252a"),
"TestObj" : {
"Slots" : NumberLong(-429496729552)
}
}
if I fetch it in php and then var_dump the result, I get:
object(stdClass)#13 (2) {
["_id"]=>
object(MongoDB\BSON\ObjectID)#11 (1) {
["oid"]=>
string(24) "569d015eb26caf586174252a"
}
["TestObj"]=>
object(stdClass)#12 (1) {
["Slots0"]=>
string(13) "-429496729552"
}
}
Notice that "Slots" became "Slots0". The appended characters seem to depend on the combination of property name and integer value. With the right values you can end up with invalid UTF8 :(
from mongo-php-driver.
I'm tracking both issues in this thread with PHPC-544 and will aim to have a fix for this in the next 1.1.x release.
from mongo-php-driver.
@jacqueswaller: The second issue you're seeing here (property name corruption) is actually independent of the first. I've diagnosed it in PHPC-592 but will be able to resolve it concurrently with the original serialization issue.
Offhand, were you at all aware that the int64 was being cast to a string by the driver? We actually log a warning, but I fear most users may be oblivious to that unless they've enabled logging. Only error/critical log messages get turned into exceptions. We certainly don't want to throw here, as that would interrupt control flow for users, but perhaps we can compromise by emitting a PHP warning in this case.
from mongo-php-driver.
Indeed, I did notice that it was coming back as a string, despite running 64-bit php/driver. When I write
print(PHP_INT_SIZE . ", " . PHP_INT_MAX);
I get
8, 9223372036854775807
I haven't done anything special for logging beyond starting mongodb with mongod.exe -logpath C:\MongoDB\logs\mongo.log
. I don't see any integer overflow warnings there, though. Unless you're talking about a php log of some kind.
from mongo-php-driver.
I haven't done anything special for logging beyond starting mongodb with
mongod.exe -logpath C:\MongoDB\logs\mongo.log
. I don't see any integer overflow warnings there, though. Unless you're talking about a php log of some kind.
@jacqueswaller: I was referring to the mongodb.debug
INI option. The C driver (i.e. libmongoc) has its own error reporting, and that INI option allows you to hook into it and capture output. This is far from ideal, as most users aren't going to run their applications with debug logging enabled (assuming they're even aware of the option). Starting in 1.2.0, we hope to raise an exception or PHP warning (see: PHP-313).
Anywho, 1.1.3 has just been released and should include the necessary fix for your issue. I'll leave this open until you can confirm that it resolves your problem. Thanks for your patience on this.
from mongo-php-driver.
Confirmed: the wrap around issue when using large numbers seems to be fixed. Doing a $set
with 4294967295 will set an Int64 in the db, $inc
will increment instead of decrementing by 1 and querying $lte
with 4294967295 gives the results I expect (instead of returning documents where TestInt <= -1). Similarly, if I then $set
over my TestInt with a small number, it converts it to an Int32 in the db. Basically everything behaves the way I'd expect it to 👍
The "returns large ints as a string" and "mangled property name" issues also both seem to be fixed (at least with the test object I provided before). var_dump now gives me
object(stdClass)#15 (2) {
["_id"]=>
object(MongoDB\BSON\ObjectID)#13 (1) {
["oid"]=>
string(24) "569d015eb26caf586174252a"
}
["MiscBin"]=>
object(stdClass)#14 (1) {
["Slots"]=>
int(-429496729552)
}
}
as expected.
from mongo-php-driver.
@jacqueswaller: Great to hear. Thanks for following up 👍
from mongo-php-driver.
Related Issues (20)
- l
- apache stop when I added extension=mongodb.so to php.ini HOT 3
- `selectServer` takes too long on official php base image (connections opened sequentially) HOT 13
- libbson Bug Report : variable ret value type error HOT 8
- No suitable servers found (`serverSelectionTryOnce` set) when rs.initiate with localhost HOT 5
- Extract mongodb-1.6.2.tgz error HOT 5
- Sporadic "Authentication failed" errors HOT 8
- MongoDB PHP Driver 1.15+ increases PHP memory consumption HOT 7
- Error while compiling on macOS HOT 7
- Major slowdown since version 1.17.0 HOT 8
- PHP Warning: PHP Startup: Unable to load dynamic library 'mongodb.so' HOT 2
- MongoDB reporting "AuthenticationAbandoned: Overridden by new authentication session" for a PHP client HOT 14
- Windows build after 1.13.0 HOT 4
- linux general protection fault , sorry for my poor english HOT 1
- PHP refusing to load MongoDB PHP driver on Windows (on one machine but not another) HOT 1
- Can't download desired extension HOT 2
- Unable to install pecl mongodb-1.15.1 in php 8.2 HOT 1
- Bug & Question: How to compile mongodb statically into PHP? HOT 9
- PHPStorm Stub for Manager class has outdated signature HOT 1
- Cannot install with laravel 11 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo-php-driver.