{"action":"created","issue":{"url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/216","repository_url":"https://api.github.com/repos/mongodb/mongo-php-library","labels_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/216/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/216/comments","events_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/216/events","html_url":"https://github.com/mongodb/mongo-php-library/issues/216","id":166573482,"number":216,"title":"php7 + opcache + mongodb: Query and php array is getting changed randomly.","user":{"login":"cb-msales","id":18257182,"avatar_url":"https://avatars.githubusercontent.com/u/18257182?v=3","gravatar_id":"","url":"https://api.github.com/users/cb-msales","html_url":"https://github.com/cb-msales","followers_url":"https://api.github.com/users/cb-msales/followers","following_url":"https://api.github.com/users/cb-msales/following{/other_user}","gists_url":"https://api.github.com/users/cb-msales/gists{/gist_id}","starred_url":"https://api.github.com/users/cb-msales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cb-msales/subscriptions","organizations_url":"https://api.github.com/users/cb-msales/orgs","repos_url":"https://api.github.com/users/cb-msales/repos","events_url":"https://api.github.com/users/cb-msales/events{/privacy}","received_events_url":"https://api.github.com/users/cb-msales/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":38,"created_at":"2016-07-20T12:51:05Z","updated_at":"2016-11-30T18:57:35Z","closed_at":null,"body":"We found some strange behaviour where queries sent to mongodb don't match what we intended to send.\n\nAfter digging deeper we found that under load with multiple requests handeled concurrently by php-fpm, the system randomly starts changing the php array (!).\nThis only happens when the array is sent to the mongodb find operation (other operations not tested).\n\nWe have only seen it changing the array when it has been sent to mongodb. Not calling ->find() does not produce the error.\n\nAlso opcache need to be enabled for the file where the query array is defined. With opcache disabled it will not fail.\n\nThe array is changed in a way that 'static' contents seem to be removed. We don't know if any more is getting replaced or changed. For example the part '[10, 12]' is replaced with NULL in our test case.\nReplacing one value with dynamic content eliminates the error too: repalce for example 12 with (int)$_GET['id'], call the test script with parameter test.php?id=10 and it will NOT fail.\n\nWhen using json_decode(json_encode($test), true) before submitting the data to ->find it will NOT fail and not change any contents of $test.\n\nThe database and selection does not exist in our test case.\n\nWe have tested with \next-mongodb 1.1.8\nmongodb/mongodb 1.0.2\nPHP 7.0.8-4\n\nBelow the test script, run with apache benchmark\n\n``` <?php\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\n$test = ['test' => ['$in' => [10, 12]]];\n\n$client = new MongoDB\\Client();\n$client->selectCollection('a','b')->find($test);\n\nfile_put_contents('/tmp/mongodb-errors.log', (int)(serialize($test) == 'a:1:{s:4:\"test\";a:1:{s:3:\"$in\";a:2:{i:0;i:10;i:1;i:12;}}}'), FILE_APPEND);\n```\n\nRun ab test:\n(optional) > sudo service php-fpm restart;\n\n> ab -c 40 -n 1000 http://your.domain.goes.here/test.php\n\nExample result: 1 = success, array not changed, 0 = error, array has been changed. '[10, 12]' has been nulled.\n\n`````` 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000\n00000000000000000000000100000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000000000111111111111111000000000000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000001111111```\n``````\n"},"comment":{"url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/comments/263961644","html_url":"https://github.com/mongodb/mongo-php-library/issues/216#issuecomment-263961644","issue_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/216","id":263961644,"user":{"login":"Visualq","id":464429,"avatar_url":"https://avatars.githubusercontent.com/u/464429?v=3","gravatar_id":"","url":"https://api.github.com/users/Visualq","html_url":"https://github.com/Visualq","followers_url":"https://api.github.com/users/Visualq/followers","following_url":"https://api.github.com/users/Visualq/following{/other_user}","gists_url":"https://api.github.com/users/Visualq/gists{/gist_id}","starred_url":"https://api.github.com/users/Visualq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Visualq/subscriptions","organizations_url":"https://api.github.com/users/Visualq/orgs","repos_url":"https://api.github.com/users/Visualq/repos","events_url":"https://api.github.com/users/Visualq/events{/privacy}","received_events_url":"https://api.github.com/users/Visualq/received_events","type":"User","site_admin":false},"created_at":"2016-11-30T18:57:35Z","updated_at":"2016-11-30T18:57:35Z","body":"@jmikola ah no I meant I was using ab -c 1 -n 100000. I didn't change the fpm config."}}
{"actor":{"display_login":"Visualq"}}