当前位置: 首页>>代码示例>>PHP>>正文


PHP MongoCursor::timeout方法代码示例

本文整理汇总了PHP中MongoCursor::timeout方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCursor::timeout方法的具体用法?PHP MongoCursor::timeout怎么用?PHP MongoCursor::timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoCursor的用法示例。


在下文中一共展示了MongoCursor::timeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $mongoDbName = $input->getArgument('mongo-db');
     $mongoCollectionName = $input->getArgument('mongo-collection');
     $mongoHost = $input->getArgument('mongo-host');
     $mongoPort = $input->getArgument('mongo-port');
     $mongoUserName = $input->getOption('mongo-user');
     $mongoPassword = $input->getOption('mongo-password');
     $options = array();
     if (!empty($mongoUserName)) {
         $options['username'] = $mongoUserName;
     }
     if (!empty($mongoPassword)) {
         $options['password'] = $mongoPassword;
     }
     $m = new MongoClient("mongodb://{$mongoHost}:{$mongoPort}", $options);
     $db = $m->{$mongoDbName};
     \MongoCursor::$timeout = -1;
     $output->writeln("Connected to the database <info>{$mongoDbName}</info>");
     $collection = $db->{$mongoCollectionName};
     $cursor = $this->getCursor($collection);
     $i = 0;
     $output->writeln("Removing elastic-search index...");
     $this->doDeleteIndex($input, $output);
     $output->writeln("Creating elastic-search index...");
     $this->doCreateIndex($input, $output);
     $output->writeln("Setting-up elastic-search mapping...");
     $this->doSetupMapping($input, $output);
     $output->writeln("\nIndexing...");
     $guzzle = $this->getGuzzle($input);
     $flag = 0;
     $nbEntries = $cursor->count(true);
     $timeStart = microtime(true);
     $requests = array();
     while ($flag == 0) {
         try {
             foreach ($cursor as $obj) {
                 $i++;
                 unset($obj['_id']);
                 $requests[] = $guzzle->put($input->getArgument('es-type') . '/' . $i, null, json_encode($obj));
                 if (0 === $i % 180) {
                     $guzzle->send($requests);
                     $requests = array();
                 }
                 if (0 === $i % 10000) {
                     $elapsedTime = microtime(true) - $timeStart;
                     $entriesPerSeconds = floor($i / $elapsedTime);
                     $output->writeln(date('H:i:s') . "\tProgress: {$i}/{$nbEntries}\t({$entriesPerSeconds}/seconds)\t" . round($i / $nbEntries * 100) . "% \t" . "~" . $this->secsToString(($nbEntries - $i) / $entriesPerSeconds) . " left\tMemory usage : " . (memory_get_usage() >> 20) . "Mo");
                 }
             }
             $flag = 1;
         } catch (Exception $ex) {
             $output->writeln("Something went wrong within MongoDB: " . $ex->getMessage() . ", Retrying ...");
             $flag = 0;
             $cursor = getCursor($collection);
         }
     }
     $output->writeln("{$i} entries processed. Took " . $this->secsToString(floor(microtime(true) - $timeStart)) . " seconds");
     return 0;
 }
开发者ID:aztech-dev,项目名称:GeonamesServer,代码行数:60,代码来源:DoIndexCommand.php

示例2: mapReduce

 /**
  * run the map/reduce
  * @static
  * @return void
  */
 public static function mapReduce()
 {
     $map = "function () {\r\n            if(arguments.callee.shipcache === undefined)\r\n            {\r\n                arguments.callee.shipcache = {}\r\n            }\r\n            if(arguments.callee.shipcache[this.victim.shipTypeID] === undefined)\r\n            {\r\n                arguments.callee.shipcache[this.victim.shipTypeID] = db.Kingboard_EveItem.findOne({typeID: parseInt(this.victim.shipTypeID)},{'marketGroup.parentGroup.marketGroupName':1});\r\n            }\r\n            var ship = arguments.callee.shipcache[this.victim.shipTypeID];\r\n            var info = {}\r\n            info[this.victim.shipType] = 1;\r\n            info[\"total\"] = 1;\r\n            if(ship != null && ship.marketGroup != null)\r\n                emit(ship.marketGroup.parentGroup.marketGroupName, info);\r\n        }";
     $reduce = "function (k, vals) {\r\n            var sums = {}\r\n            var total = 0;\r\n            vals.forEach(function(info) {\r\n                info[\"total\"] = 0;\r\n                for (var key in info)\r\n                {\r\n                    if(sums[key] === undefined)\r\n                        sums[key] = 0;\r\n                    sums[key] += info[key];\r\n                    total += info[key];\r\n                }\r\n            });\r\n            sums[\"total\"] = total;\r\n            return sums;\r\n        }";
     // we want the map/reduce to run for as long as it takes
     MongoCursor::$timeout = -1;
     return King23_Mongo::mapReduce("Kingboard_Kill", __CLASS__, $map, $reduce);
 }
开发者ID:holdensmagicalunicorn,项目名称:Kingboard,代码行数:13,代码来源:Kingboard_Kill_MapReduce_KillsByShip.php

示例3: __construct

 /**
  * 
  * @param \MongoDb $db
  * @param \Mongodloid_Connection $connection
  */
 public function __construct(\MongoDb $db, \Mongodloid_Connection $connection)
 {
     parent::__construct($db, $connection);
     $this->collections = Billrun_Factory::config()->getConfigValue('db.collections', array());
     $timeout = Billrun_Factory::config()->getConfigValue('db.timeout', 3600000);
     // default 60 minutes
     Billrun_Factory::log()->log('Set database cursor timeout to: ' . $timeout, Zend_Log::INFO);
     MongoCursor::$timeout = $timeout;
 }
开发者ID:kalburgimanjunath,项目名称:system,代码行数:14,代码来源:Db.php

示例4: testStaticTimeout

 /**
  * @expectedException MongoCursorTimeoutException
  */
 public function testStaticTimeout()
 {
     $this->markTestSkipped("for now");
     return;
     MongoCursor::$timeout = 1;
     for ($i = 0; $i < 1000; $i++) {
         $this->object->insert(array("x" => "sdfjnaireojaerkgmdfkngkdsflngklsgntoigneorisgmsrklgd{$i}", "y" => $i));
     }
     $rows = $this->object->find(array('$eval' => 'r = 0; cursor = db.c.find(); while (cursor.hasNext()) { x = cursor.next(); for (i=0; i<200; i++) { if (x.name == "joe"+i) { r++; } } } return r;'));
     foreach ($rows as $row) {
     }
     MongoCursor::$timeout = 30000;
 }
开发者ID:kph11,项目名称:mongo-php-driver,代码行数:16,代码来源:SlowTests.php

示例5: __construct

 /**
  * 
  * @param \MongoDb $db
  * @param \Mongodloid_Connection $connection
  */
 public function __construct(\MongoDb $db, \Mongodloid_Connection $connection)
 {
     parent::__construct($db, $connection);
     // TODO: refatoring the collections to factory (loose coupling)
     $this->collections = Billrun_Factory::config()->getConfigValue('db.collections', array());
     $timeout = Billrun_Factory::config()->getConfigValue('db.timeout', 3600000);
     // default 60 minutes
     if ($this->compareClientVersion('1.5.3', '<')) {
         Billrun_Factory::log()->log('Set database cursor timeout to: ' . $timeout, Zend_Log::INFO);
         @(MongoCursor::$timeout = $timeout);
     } else {
         // see also bugs:
         // https://jira.mongodb.org/browse/PHP-1099
         // https://jira.mongodb.org/browse/PHP-1080
         $db->setWriteConcern($db->getWriteConcern()['w'], $timeout);
     }
 }
开发者ID:ngchie,项目名称:system,代码行数:22,代码来源:Db.php

示例6: testGlobalTimeout

 /**
  * Test global timeouts and native mappings
  */
 public function testGlobalTimeout()
 {
     // Create collection
     $default_timeout = \MongoCursor::$timeout;
     $collection = $this->getTestCollection();
     // Create a cursor object
     $cursor = $collection->find();
     $native_cursor = $cursor->native;
     // Assert cursor timeouts are updated
     $this->assertEquals($cursor::$timeout, $native_cursor::$timeout);
     // Check that static timeouts are binded
     $default_timeout = \MongoCursor::$timeout;
     $cursor::$timeout = $default_timeout / 2;
     $this->assertEquals(\MongoCursor::$timeout, $cursor::$timeout);
     $this->assertEquals(\MongoMinify\Cursor::$timeout, $cursor::$timeout);
     \MongoCursor::$timeout = 200;
     $this->assertEquals(\MongoCursor::$timeout, \MongoMinify\Cursor::$timeout);
     $this->assertEquals(\MongoMinify\Cursor::$timeout, 200);
     \MongoCursor::$timeout = $default_timeout;
 }
开发者ID:marcqualie,项目名称:mongominify,代码行数:23,代码来源:CursorTest.php

示例7: getCursor

 /**
  *
  * @return \MongoCursor
  */
 private function getCursor()
 {
     if ($this->cursor) {
         return $this->cursor;
     }
     $this->cursor = $this->collection->getMongoCollection()->find($this->expression->toArray(), $this->fields);
     if ($this->skip) {
         $this->cursor->skip($this->skip);
     }
     if ($this->limit) {
         $this->cursor->limit($this->limit);
     }
     if ($this->options['batchSize']) {
         $this->cursor->batchSize($this->options['batchSize']);
     }
     if ($this->options['clientTimeout']) {
         $this->cursor->timeout($this->options['clientTimeout']);
     }
     if ($this->options['serverTimeout']) {
         $this->cursor->maxTimeMS($this->options['clientTimeout']);
     }
     if ($this->sort) {
         $this->cursor->sort($this->sort);
     }
     if ($this->hint) {
         $this->cursor->hint($this->hint);
     }
     // log request
     if ($this->client->hasLogger()) {
         $this->client->getLogger()->debug(get_called_class() . ': ' . json_encode(array('collection' => $this->collection->getName(), 'query' => $this->expression->toArray(), 'project' => $this->fields, 'sort' => $this->sort)));
     }
     $this->cursor->rewind();
     // define read preferences
     if ($this->readPreference) {
         $this->cursor->setReadPreference($this->readPreference['type'], $this->readPreference['tagsets']);
     }
     return $this->cursor;
 }
开发者ID:paulocarvalhodesign,项目名称:php-mongo,代码行数:42,代码来源:Cursor.php

示例8: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('collection');
     $idmodule = $input->getArgument('module');
     $dbname = $input->getArgument('dbname');
     $usermail = $input->getArgument('usermail');
     if ($id && $idmodule && $dbname && $usermail) {
         $orphans = array();
         $error = '';
         $dm = $this->getContainer()->get('doctrine.odm.mongodb.document_manager');
         $dm->getConfiguration()->setDefaultDB($dbname);
         $configuration = $dm->getConnection()->getConfiguration();
         $configuration->setLoggerCallable(null);
         \MongoCursor::$timeout = -1;
         $module = $dm->getRepository('PlantnetDataBundle:Module')->find($idmodule);
         if (!$module) {
             $error = 'Unable to find Module entity.';
         }
         if ($module->getType() == 'text') {
             $error = 'Module entity: Wrong type.';
         }
         if (empty($error)) {
             /*
              * Open the uploaded csv
              */
             $csvfile = __DIR__ . '/../Resources/uploads/' . $module->getCollection()->getAlias() . '/' . $module->getAlias() . '.csv';
             $handle = fopen($csvfile, "r");
             /*
              * Get the module properties
              */
             $columns = fgetcsv($handle, 0, ";");
             $fields = array();
             $attributes = $module->getProperties();
             foreach ($attributes as $field) {
                 $fields[] = $field;
             }
             $s = microtime(true);
             $batchSize = 100;
             $size = 0;
             $rowCount = 0;
             $errorCount = 0;
             if ($module->getType() == 'image') {
                 while (($data = fgetcsv($handle, 0, ';')) !== false) {
                     $num = count($data);
                     $image = new Image();
                     $attributes = array();
                     for ($c = 0; $c < $num; $c++) {
                         $value = trim($this->data_encode($data[$c]));
                         //check for int or float value
                         if (is_numeric($value)) {
                             $tmp_value = intval($value);
                             if ($value == $tmp_value) {
                                 $value = $tmp_value;
                             } else {
                                 $tmp_value = floatval($value);
                                 if ($value == $tmp_value) {
                                     $value = $tmp_value;
                                 }
                             }
                         }
                         //
                         $attributes[$fields[$c]->getId()] = $value;
                         switch ($fields[$c]->getType()) {
                             case 'file':
                                 $image->setPath($value . '');
                                 break;
                             case 'copyright':
                                 $image->setCopyright($value . '');
                                 break;
                             case 'idparent':
                                 $image->setIdparent($value . '');
                                 break;
                             case 'idmodule':
                                 $image->setIdentifier($value . '');
                                 break;
                         }
                     }
                     $image->setProperty($attributes);
                     $image->setModule($module);
                     $parent = null;
                     if ($module->getParent()) {
                         $parent_q = $dm->createQueryBuilder('PlantnetDataBundle:Plantunit')->field('module.id')->equals($module->getParent()->getId())->field('identifier')->equals($image->getIdparent())->getQuery()->execute();
                         foreach ($parent_q as $p) {
                             $parent = $p;
                         }
                     }
                     if ($parent) {
                         $image->setPlantunit($parent);
                         $image->setTitle1($parent->getTitle1());
                         $image->setTitle2($parent->getTitle2());
                         $image->setTitle3($parent->getTitle3());
                         $dm->persist($image);
                         $rowCount++;
                         $size++;
                         if (!$parent->getHasimages()) {
                             $parent->setHasimages(true);
                             $dm->persist($parent);
                             $size++;
                         }
                         //update Taxons
//.........这里部分代码省略.........
开发者ID:plantnet,项目名称:plantnet-publish,代码行数:101,代码来源:ImportationCommand.php

示例9: update

 /**
  * Update a document
  *
  * @param string $collection Name of the collection
  * @param array  $options    Array of update options
  *
  * @throws Exception
  * @access public
  * @return boolean
  */
 public function update($collection = '', $options = array())
 {
     if (empty($collection)) {
         throw new \MongoQB\Exception('No Mongo collection selected to
          update');
     }
     if (count($this->updates) === 0) {
         throw new \MongoQB\Exception('Nothing to update in Mongo collection or
          update is not an array');
     }
     try {
         \MongoCursor::$timeout = -1;
         $options = array_merge(array($this->_querySafety => true, 'multiple' => false), $options);
         $result = $this->_dbhandle->{$collection}->update($this->wheres, $this->updates, $options);
         $this->_clear($collection, 'update');
         if ($result['updatedExisting'] > 0) {
             return $result['updatedExisting'];
         }
         // @codeCoverageIgnoreStart
         return false;
         // @codeCoverageIgnoreEnd
     } catch (\MongoCursorException $Exception) {
         throw new \MongoQB\Exception('Update of data into MongoDB failed: ' . $Exception->getMessage());
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:fahmiardi,项目名称:mongoqb,代码行数:36,代码来源:Builder.php

示例10: update_punit

 private function update_punit($dm, $module, $dbname, $usermail)
 {
     \MongoCursor::$timeout = -1;
     $idmodule = $module->getId();
     $this->reset_taxo($dm, $module);
     $csvfile = __DIR__ . '/../Resources/uploads/' . $module->getCollection()->getAlias() . '/' . $module->getAlias() . '.csv';
     $handle = fopen($csvfile, "r");
     $columns = fgetcsv($handle, 0, ";");
     $fields = array();
     $attributes = $module->getProperties();
     foreach ($attributes as $field) {
         $fields[] = $field;
     }
     //Punit identifiers in the csv file
     $csv_ids = array();
     while (($data = fgetcsv($handle, 0, ';')) !== false) {
         $num = count($data);
         for ($c = 0; $c < $num; $c++) {
             if ($fields[$c]->getType() == 'idmodule') {
                 $value = trim($this->data_encode($data[$c]));
                 $csv_ids[] = $value;
             }
         }
     }
     fclose($handle);
     //get existing ids in database
     $db_ids = array();
     $punits = $dm->createQueryBuilder('PlantnetDataBundle:Plantunit')->hydrate(false)->select('identifier')->field('module')->references($module)->getQuery()->execute();
     foreach ($punits as $id) {
         $db_ids[] = $id['identifier'];
     }
     $punits = null;
     unset($punits);
     $ids_to_remove = array_diff($db_ids, $csv_ids);
     if (count($ids_to_remove)) {
         $sub_ids_to_remove = array_chunk($ids_to_remove, 100);
         foreach ($sub_ids_to_remove as $tab_ids) {
             //delete
             //deletes punits where id is not in csv_ids
             $dm->createQueryBuilder('PlantnetDataBundle:Plantunit')->remove()->field('identifier')->in($tab_ids)->getQuery()->execute();
             //cascade doesnt work !?
             $dm->createQueryBuilder('PlantnetDataBundle:Image')->remove()->field('idparent')->in($tab_ids)->getQuery()->execute();
             $dm->createQueryBuilder('PlantnetDataBundle:Location')->remove()->field('idparent')->in($tab_ids)->getQuery()->execute();
             $dm->createQueryBuilder('PlantnetDataBundle:Other')->remove()->field('idparent')->in($tab_ids)->getQuery()->execute();
         }
     }
     $csv_ids = null;
     unset($csv_ids);
     $db_ids = null;
     unset($db_ids);
     $ids_to_remove = null;
     unset($ids_to_remove);
     //update / create Punits
     $handle = fopen($csvfile, "r");
     $columns = fgetcsv($handle, 0, ";");
     $batchSize = 100;
     $size = 0;
     while (($data = fgetcsv($handle, 0, ';')) !== false) {
         $csv_id = null;
         $num = count($data);
         for ($c = 0; $c < $num; $c++) {
             if ($fields[$c]->getType() == 'idmodule') {
                 $value = trim($this->data_encode($data[$c]));
                 $csv_id = $value;
             }
         }
         if ($csv_id) {
             $update = true;
             $subupdate = false;
             //update
             //updates punits where id is in csv_ids
             $plantunit = $dm->getRepository('PlantnetDataBundle:Plantunit')->findOneBy(array('module.id' => $module->getId(), 'identifier' => $csv_id));
             //create
             //creates punits where csv_id is not in id
             if (!$plantunit) {
                 $update = false;
                 $plantunit = new Plantunit();
                 $plantunit->setModule($module);
             }
             $attributes = array();
             for ($c = 0; $c < $num; $c++) {
                 $value = trim($this->data_encode($data[$c]));
                 //check for int or float value
                 if (is_numeric($value)) {
                     $tmp_value = intval($value);
                     if ($value == $tmp_value) {
                         $value = $tmp_value;
                     } else {
                         $tmp_value = floatval($value);
                         if ($value == $tmp_value) {
                             $value = $tmp_value;
                         }
                     }
                 }
                 //
                 $attributes[$fields[$c]->getId()] = $value;
                 switch ($fields[$c]->getType()) {
                     case 'idmodule':
                         $plantunit->setIdentifier($value . '');
                         break;
//.........这里部分代码省略.........
开发者ID:plantnet,项目名称:plantnet-publish,代码行数:101,代码来源:UpdateCommand.php

示例11: api_submodule_geodataAction

 /**
  * @ApiDoc(
  *  section="Publish v2 - GeoData. Sub-module entity [type = locality]",
  *  description="Returns geo data from a 'locality' sub-module entity [GeoJson]",
  *  statusCodes={
  *      200="Returned when: Successful",
  *      401="Returned when: Unauthorized client",
  *      404="Returned when: Resource not found"
  *  },
  *  filters={
  *      {"name"="project", "dataType"="String", "required"=true, "description"="Project url"},
  *      {"name"="collection", "dataType"="String", "required"=true, "description"="Collection url"},
  *      {"name"="module", "dataType"="String", "required"=true, "description"="Module url"},
  *      {"name"="submodule", "dataType"="String", "required"=true, "description"="'Location' Sub-Module url"}
  *  }
  * )
  *
  * @Route(
  *      "/{project}/{collection}/{module}/{submodule}/geodata",
  *      name="api_submodule_geodata"
  * )
  * @Method("get")
  */
 public function api_submodule_geodataAction($project, $collection, $module, $submodule)
 {
     ini_set('memory_limit', '-1');
     //check project
     try {
         ControllerHelp::check_enable_project($project, $this->get_prefix(), $this);
     } catch (\Exception $e) {
         $this->return_404_not_found($e->getMessage());
         exit;
     }
     //init
     $dm = $this->get('doctrine.odm.mongodb.document_manager');
     $dm->getConfiguration()->setDefaultDB($this->get_prefix() . $project);
     $result = array();
     //get language config
     $config = ControllerHelp::get_config($project, $dm, $this);
     $this->check_authorized_client($config);
     //data1
     $collection = $dm->getRepository('PlantnetDataBundle:Collection')->findOneBy(array('url' => $collection));
     if (!$collection || $collection->getDeleting() == true) {
         $this->return_404_not_found('Unable to find Collection entity.');
         exit;
     }
     $module = $dm->getRepository('PlantnetDataBundle:Module')->findOneBy(array('url' => $module, 'collection.id' => $collection->getId()));
     if (!$module || $module->getType() != 'text' || $module->getDeleting() == true) {
         $this->return_404_not_found('Unable to find Module entity.');
         exit;
     }
     $submodule = $dm->getRepository('PlantnetDataBundle:Module')->findOneBy(array('url' => $submodule, 'parent.id' => $module->getId(), 'collection.id' => $collection->getId()));
     if (!$submodule || $submodule->getType() == 'text' || $submodule->getDeleting() == true) {
         $this->return_404_not_found('Unable to find Sub-module entity.');
         exit;
     }
     if ($submodule->getType() != 'locality') {
         $this->return_404_not_found('Unable to find geo data for this Sub-module entity.');
         exit;
     }
     //data2
     $display = array();
     $field = $module->getProperties();
     foreach ($field as $row) {
         if ($row->getMain() == true) {
             $display[] = $row->getId();
         }
     }
     $field_sub = $submodule->getProperties();
     $field_sub_tab = array();
     foreach ($field_sub as $f) {
         if ($f->getDetails() == true) {
             $field_sub_tab[$f->getId()] = StringHelp::cleanToKey($f->getName());
         }
     }
     \MongoCursor::$timeout = -1;
     $locations = $dm->createQueryBuilder('PlantnetDataBundle:Location')->hydrate(false)->select('title1')->select('title2')->select('title3')->select('property')->select('latitude')->select('longitude')->select('idparent')->field('module')->references($submodule)->getQuery()->execute()->toArray();
     array_walk($locations, function (&$item, $key, $field_sub_tab) {
         $l = array('type' => 'Feature', 'geometry' => array('type' => 'Point', 'coordinates' => array($item['longitude'], $item['latitude'])), 'properties' => array('title1' => $item['title1'], 'title2' => $item['title2'], 'title3' => $item['title3'], 'parent_identifier' => $item['idparent']));
         foreach ($item['property'] as $key => $value) {
             if (array_key_exists($key, $field_sub_tab)) {
                 $l['properties'][$field_sub_tab[$key]] = $value;
             }
         }
         $item = $l;
     }, $field_sub_tab);
     $locations = array_values($locations);
     //response
     $response = new Response(json_encode(array('type' => 'FeatureCollection', 'features' => $locations)));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
开发者ID:plantnet,项目名称:plantnet-publish,代码行数:92,代码来源:ApiController.php

示例12: sprintf

   echo 'Total : ' . sprintf('%01.6f', microtime(true) - $startTime) . ' seconds.<br />';
   exit;*/
 if (DO_MYSQL) {
     $mysqlConnection = mysql_connect('127.0.0.1', 'root', 'password');
     mysql_select_db('cps2_perf_test');
 }
 if (DO_CPS) {
     $cpsConnection->sendRequest(new CPS_Request('clear'));
     sleep(1);
 }
 //  $cpsConnection->waitForResponse(false);
 if (DO_MONGO) {
     $m = new Mongo();
     $db = $m->test;
     $collection = $db->insert_test;
     MongoCursor::$timeout = 120000;
     // 2 minutes
 }
 if (defined('RANDOM_SEED')) {
     srand(RANDOM_SEED);
     echo 'Seeded with random seed ' . RANDOM_SEED . ', first random value: ' . rand() . '<br />';
 }
 $randomWords = array();
 $wordChars = '0123456789abcdefghijklmnopqrstuvwxyz';
 $charCount = strlen($wordChars);
 define('WORD_COUNT', 100000);
 for ($x = 0; $x < WORD_COUNT; ++$x) {
     $size = rand(3, 9);
     $word = '';
     for ($y = 0; $y < $size; ++$y) {
         $word .= $wordChars[rand(0, $charCount - 1)];
开发者ID:philippineglobaloutsourcing,项目名称:laravel-git,代码行数:31,代码来源:insert_test.php

示例13: group

 public static function group($collection, $keys = [], $query = [], $count = [], $sum = [], $sort = [], $limit = null)
 {
     global $debug;
     // Turn keys into an array if is isn't already an array
     if (!is_array($keys)) {
         $keys = [$keys];
     }
     // Start the aggregation pipeline with the query
     $pipeline = [];
     if (sizeof($query)) {
         $pipeline[] = ['$match' => $query];
     }
     // Create the group by using the given key(s)
     $ids = [];
     foreach ($keys as $key => $value) {
         if (is_numeric($key)) {
             $ids[] = '$' . $value;
         } else {
             $ids[$key] = ['$' . $key => '$' . $value];
         }
     }
     if (sizeof($ids) == 1 && isset($ids[0])) {
         $ids = $ids[0];
     }
     $group = [];
     $group['_id'] = $ids;
     // If no counts or sums are given, assume a count based on the keys for the $group
     if (sizeof($count) == 0 && sizeof($sum) == 0) {
         $group['count'] = ['$sum' => 1];
     }
     // Include counts in the $group
     if (!is_array($count)) {
         $count = [$count];
     }
     foreach ($count as $s) {
         $group[str_replace('.', '_', $s) . 'Count'] = ['$sum' => 1];
     }
     // Include sums in the $group
     if (!is_array($sum)) {
         $sum = [$sum];
     }
     foreach ($sum as $s) {
         $group[str_replace('.', '_', $s) . 'Sum'] = ['$sum' => '$' . $s];
     }
     // Add the group to the pipeline
     $pipeline[] = ['$group' => $group];
     // $project the keys into the result
     $project = [];
     $project['_id'] = 0;
     foreach ($keys as $key => $value) {
         if (is_numeric($key)) {
             $project[$value] = '$_id';
         } else {
             $project[$key] = '$_id.' . $key;
         }
     }
     if (sizeof($count) == 0 && sizeof($sum) == 0) {
         $project['count'] = 1;
     }
     if (sizeof($count) > 0) {
         foreach ($count as $s) {
             $project[str_replace('.', '_', $s) . 'Count'] = 1;
         }
     }
     if (sizeof($sum) > 0) {
         foreach ($sum as $s) {
             $project[str_replace('.', '_', $s) . 'Sum'] = 1;
         }
     }
     $pipeline[] = ['$project' => $project];
     // Assign the sort to the pipeline
     if (sizeof($sort) > 0) {
         $pipeline[] = ['$sort' => $sort];
     }
     // And add the limit
     if ($limit != null) {
         $pipeline[] = ['$limit' => (int) $limit];
     }
     // Prep the cursor
     $mdb = new self();
     $collection = $mdb->getCollection($collection);
     if (!$debug) {
         MongoCursor::$timeout = -1;
     }
     // this should be deprecated but aggregate doesn't have a timeout
     // Execute the query
     $result = $collection->aggregate($pipeline);
     if ($result['ok'] == 1) {
         return $result['result'];
     }
     throw new Exception('pipeline query failure');
 }
开发者ID:nasimnabavi,项目名称:zKillboard,代码行数:92,代码来源:Mdb.php

示例14: setTimeout

    /**
     * setTimeout Method
     *
     * Sets the MongoCursor timeout so long queries (like map / reduce) can run at will.
     * Expressed in milliseconds, for an infinite timeout, set to -1
     *
     * @param int $ms
     * @return boolean
     * @access public
     */
    public function setTimeout($ms) {
        MongoCursor::$timeout = $ms;

        return true;
    }
开发者ID:nishant-shrivastava,项目名称:test-mongo-db,代码行数:15,代码来源:mongodb_source.php

示例15: Distinct

 /**
  * distinct查询
  * @param $field
  * @param $conds
  * @return array
  * @throws Exception
  */
 public function Distinct($field, $conds)
 {
     $callback = function ($collection) use($field, $conds) {
         return $collection->Distinct($field, $conds);
     };
     try {
         MongoCursor::$timeout = 120000;
         $cursor = $this->_doAction($callback);
         //$cursor->timeout(120000);
     } catch (Exception $ex) {
         throw new Exception(__METHOD__ . ' Distinct fail! Exception code: ' . $ex->getCode() . ' msg: ' . $ex->getMessage(), self::ERRNO_FINDONE_FAIL);
     }
     $ret = $this->UnCompress($cursor);
     return $ret;
 }
开发者ID:vincenttone,项目名称:daf,代码行数:22,代码来源:db.php


注:本文中的MongoCursor::timeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。