Running this full PHP script. When the process ends, the file is not written.
<?php require __DIR__ . '/../vendor/autoload.php'; $client = new MongoDB\Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/'); $database = $client->selectDatabase('test'); $database->drop(); $gridfs = $database->selectGridFSBucket(); // Open a stream for writing, similar to fopen with mode 'w' $stream = $gridfs->openUploadStream('hello.txt'); fwrite($stream, 'Hello world!');
To get the file written, the stream must be explicitly closed.
fclose($stream);
Note that the stream is correctly closed when this code is wrapped inside a function.
- is related to
-
PHPLIB-345 GridFS stream close handler may error during shutdown
- Closed