downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoGridFS::storeUpload> <MongoGridFS::storeBytes
[edit] Last updated: Fri, 18 Sep 2009

view this page in

MongoGridFS::storeFile

(PECL mongo >=0.9.0)

MongoGridFS::storeFileStores a file in the database

Описание

public mixed MongoGridFS::storeFile ( string $filename [, array $extra = array() ] )

Параметри

filename

The name of the file.

extra

Other metadata to add to the file saved.

Връщани стойности

Returns the _id of the saved object.



add a note add a note User Contributed Notes MongoGridFS::storeFile
mike at eastghost dot com 16-Feb-2012 01:50
Pass

$options['safe'] = true;

to make Mongo slow down and do inserts sequentially instead of in parallel.

Use case:

I had 274 PDF documents stored on ext3 disk (avg. size was 5MB, none over 20MB)

A PHP loop loaded each PDF, then did a $GridFS->storeFile( $data, $meta );

This caused server to spike from load average of 0.2 to over 20.0

Apparently what was happening is the loop slammed Mongo (then memory, disk) with 274 convert/stores to do all at once.

Adding

$GridFS->storeFile( $data, $meta, array( 'safe' => true ) );

made the loop slow down and wait for each insert to finish and be confirmed before going on to next PDF.

Moral: Safe option can be used to maintain sanity and is not always just for data validity.
mike at eastghost dot com 16-Feb-2012 01:31
A little confusing, but the "string $filename" (i.e., the first parameter) is the actual data that gets stored into the GridFS.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites