"If the document"...

serialization (missing a) — also, please not more than one line of whitespace. You can probably improve the formatting here as well.

What happens if you call this and php_mongo_api_write_start() has not been called?