You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you use this strategy you MUST close your Mongo connection on the spork.pre_fork event.
$mongo = new Mongo();
$manager->addListener(Events::PRE_FORK, array($mongo, 'close'));
I can not understand why I need to do this?
Also my code looks like, I mean that I open connection out of logic closure that runs inside fork.
$mongo = new \MongoClient();
$db = $mongo->selectDB(DB_NAME);
$coll = $db->selectCollection(COLL_NAME);
$cursor = $coll->find([/*some query here*/]);
$dispatcher = newSporkDispatcher\EventDispatcher();
$dispatcher->addListener(SporkDispatcher\Events::PRE_FORK, function() use($mongo) {
$mongo->close();
});
$manager = newSpork\ProcessManager($dispatcher);
$strategy = newSpork\Batch\Strategy\MongoStrategy(5);
$manager->process($cursor, function($document) {
$document; // some work here
}, $strategy);
There are few more questions:
if I close connection BEFORE any forking operation, what will be with cursor?
will cursor close as well as connection?
will forked process open new connection inside it-self, or what?
Hi, I have found next in
MongoStrategy
I can not understand why I need to do this?
Also my code looks like, I mean that I open connection out of
logic closure
that runs inside fork.There are few more questions:
So, looks like @kriswallsmith will be helpful here.
The text was updated successfully, but these errors were encountered: