I get this error on PHP7 every about 100 requests for some odd reason and I cannot get rid of it until I restart the fpm demon, however, the real problem is I cannot explain what the error is to start diagnosing this.
I took a look at the documentation http://php.net/manual/en/function.json-last-error.php which was not very useful and there does not seem to be any real links hanging about.
I know this error is not actually related to recursion depth (JSON_ERROR_DEPTH
) so what does this error actually mean?
This is the var_dump()
of the array that is failing:
array (
'ns' => 'user',
'where' => '{"_id":"MongoDB\\\\BSON\\\\ObjectID(5505a4f647ac1824618b4567)","status":10}',
'projection' =>
array (
),
'sort' =>
array (
),
'limit' => NULL,
'skip' => NULL,
)
JSON_ERROR_RECURSION
indicates that the data passed to json_encode()
contains one or more recursive references.
$data = array();
$data['foo'] = &$data; // <-- recursive reference here
var_dump(json_encode($data)); // bool(false)
var_dump(json_last_error_msg()); // string(18) "Recursion detected"
var_dump(json_last_error() === JSON_ERROR_RECURSION); // bool(true)
Code like this will work though:
$data['foo'] = 'hello';
$data['bar'] = &$data['foo'];
But not like this (another recursive reference):
$data['foo'] = [1, 2, 3];
$data['foo'][] = &$data['foo'];
Recursive reference means that the reference points to a variable that in turn contains the same reference again.
Most likely need to update mongodb driver (or maybe another extension). Extension with bug may write to shared memory (immutable arrays) - it is not allowed.
It is can be detected with opcache.protect_memory
(http://php.net/manual/en/opcache.configuration.php#ini.opcache.protect-memory)