PHP Classes

MongoDB Queue PHP Query Execute: Query and execute multiple queries using MongoDB

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 75 All time: 10,189 This week: 206Up
Version License PHP version Categories
mongodb-php-concurre 1.0.0MIT/X Consortium ...5PHP 5, Databases
Description 

Author

This package can queue and execute multiple queries using MongoDB.

It creates a queue that contains a list of MongoDB queries to be execute associated to callback functions.

The class can also run the queries traversing the queue by executing one by one and invoking the respective callback function once each one is done.

Picture of LAGGOUNE Walid
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

 

Example

<?php
require_once __DIR__ . "/vendor/autoload.php";
$collection = (new MongoDB\Client)->myDb;
$m = new MongoConcurrency\Mongo($collection);
$textData = [];
$options = [];
$intData = [];
echo
"Generating test data ... ";
for (
$i=1; $i <= 10000 ; $i++) {
   
array_push($intData, [$i => $i]);
}
for (
$i=0; $i <= 5000 ; $i++) {
   
array_push($textData, ["name" => "john"]);
}
echo
"[+] \n";

$m->selectFrom("test1", [], 3, function(iterable $results) {
    echo
" [+] End select : ".sizeof($results)."\n";
});
$m->insertTo("test2", $textData, 3, function() {
    echo
" [+] End insert \n";
});
$m->updateFrom("test2", ["name" => "john"], ["name" => "alex"], 3, function(int $modified) {
    echo
" [+] End update : ".$modified." \n";
});
$m->deleteFrom("test2", ["name" => "john"], 3, function(int $intDataeleted) {
    echo
" [+] End delete : ".$intDataeleted."\n";
});
$m->run();


Details

mongodb-php-concurrency

Concurrency PHP library for MongoDB

Requirements

  • PHP >= 7.2
  • Ev extension http://docs.php.net/manual/en/ev.setup.php
    ### Install
    sudo composer require mongo-concurrency/mongo-concurrency @dev
    ### Examples
    <?php
    require_once __DIR__ . "/vendor/autoload.php";
    $collection 	= 	(new MongoDB\Client)->myDb;
    $m		= 	new MongoConcurrency\Mongo($collection);
    $textData	=	  [];
    $options 	=	  []; 
    $intData 	= 	[];
    echo "Generating test data ... ";
    for ($i=1; $i <= 10000  ; $i++) { 
    array_push($intData, [$i => $i]);
    }
    for ($i=0; $i <= 5000 ; $i++) { 
    array_push($textData, ["name" => "john"]);
    }
    echo "[+] \n";
    
    

// select from test1 for 5 seconds with no options array (options is the filter array in : https://docs.mongodb.com/php-library/v1.2/reference/method/MongoDBCollection-findOne/#phpmethod.MongoDB\Collection::findOne) $m->selectFrom("test1", [], 5, function(iterable $results) {

echo "  [+] End select : ".sizeof($results)."\n";

});

// insert in to test2 array textData for 1 second $m->insertTo("test2", $textData, 1, function() {

echo "  [+] End insert \n";

});

// update from test2 where name = john to name = alex for 6 seconds $m->updateFrom("test2", ["name" => "john"], ["name" => "alex"], 6, function(int $modified) {

echo " [+] End update : ".$modified." \n";

});

// delete from test2 where name = john for 5 seconds $m->deleteFrom("test2", ["name" => "john"], 5, function(int $intDataeleted) {

echo " [+] End delete : ".$intDataeleted."\n";

}); $m->run();

### Results 
Image of Results

  Files folder image Files (678)  
File Role Description
Files folder imagesrc (1 file)
Files folder imagevendor (1 file, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:75
This week:0
All time:10,189
This week:206Up