There already function(s) for that, in shared_cursor.c: php_mongo_get_cursor_id and php_mongo_get_cursor_first_batch which I (had) refactored in https://github.com/mongodb/mongo-php-driver/pull/622/files#diff-c0e66d0d56d8293d002202a4108dcc09L250 to fetch all three types in one go. This refactored method in shared_cursor.c is what should be done here.