mongo-concurrency/mongo-concurrency

Concurrency PHP library for MongoDB

dev-master 2020-03-03 23:49 UTC

This package is auto-updated.

Last update: 2024-04-30 00:35:30 UTC


README

Concurrency PHP library for MongoDB

Requirements

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