• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MongoDB - Ekino PHP
 

MongoDB - Ekino PHP

on

  • 3,680 views

Overview mongodb in application with PHP.

Overview mongodb in application with PHP.

Sub-annexe:
http://www.ekino.com/
http://www.florentdenis.net/
https://github.com/pokap/pool-dbm

Statistics

Views

Total Views
3,680
Views on SlideShare
3,506
Embed Views
174

Actions

Likes
0
Downloads
7
Comments
0

3 Embeds 174

http://pokap.io 136
http://www.pokap.io 37
http://feedly.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Qu&apos;est-ce que le no-sql ? <br /> Tout ce qui n&apos;est pas SQL <br /> Le no-sql a toujours existé <br />
  • Clé-valeur <br /> Orienté columns <br /> Orienté document <br />
  • Pas de transaction <br /> Terminologie : <br /> Table = Collection, <br /> Ligne = Document, <br /> Index = Index <br /> Collections de collections <br /> Mongo: ACID ? ~Atomic (update)~, cohérent, isolation, durable <br />
  • Pas de schéma <br /> Donnée hétérogènes (éviter M coll) <br /> Atomicité par document <br /> Terminologie : <br /> Jointure = Données embarquées <br />
  • Obligatoire <br /> Clé 12 bits <br /> 4 – timestamp <br /> 3 – id machine <br /> 2 – id process <br /> 3 – compteur <br /> Non brut visible en hexa 24 caractères <br />
  • Donne une idée de l&apos;implémentation de mongo dans PHP <br />
  • Pas besoin de createdAt avec l&apos;id <br />
  • Upsert : insert if unexists <br /> Multiple : all for request <br /> J : false : force sync with disk, else journal <br />
  • Groupe de process mongo maintiens les mêmes données (master/slave) <br />
  • Process stockage de donnée entre plusieurs machine. <br /> Si une machine ne tiens pas la charge (I/O) <br /> Haute-disponibilité avec la réplication <br />
  • Qu&apos;est-ce que le no-sql ? <br /> Tout ce qui n&apos;est pas SQL <br /> Le no-sql a toujours existé <br />
  • Compatible : Mac, windows et Linux <br />
  • - ne pas l&apos;utiliser juste pour le plaisir <br /> - pas adapté aux environnements transactionnels critiques <br />

MongoDB - Ekino PHP MongoDB - Ekino PHP Presentation Transcript

  • MongoDB – Partie 1
  • What the no-sql ?
  • Introduction
  • Introduction PHPCR
  • MongoDB
  • MongoDB – Infos MongoDB ("humongous") 10gen 2007 – start project 2009 – open source C++ Licence : GNU AGPL v3.0 (drivers: Apache licence) Easy, scalability and Big DATA Geolocalisation
  • Data MongoDB MySQL SGDB > databases > collections > documents SGDB > databases > tables > lignes No structure Dynamic schema Structure Static schema
  • Data BSON = Binary JSON Lightweight, traversable and UTF-8 { FirstName: Address: Children: {Name: {Name: {Name: {Name: ] } "Jonathan", "15 Wanamassa Point Road", [ "Michael", Age: 10}, "Jennifer", Age: 8}, "Samantha", Age: 5}, "Elena", Age: 2}
  • Key _id: ObjectId 12 bits : - 4 bits – Timestamp (Unix) - 3 bits – ID machine - 2 bits – ID process - 3 bits – Count } Similar UUID Example : 52af1a617e0b18d9448b4567 (hexa) DBRefs - collection - _id - db (optional)
  • Map reduce Map : select process per document Reduce : combining data function mapFunction() { emit(this.user_id, this.price); } function reduceFunction(keyUserId, valuePrice) { return Array.sum(valuePrice); } db.runCommand({ mapReduce: 'my_collection', map: mapFunction, Reduce: reduceFunction, out: 'map_reduce_results_collection', query: { old_date: { $gt: new Date('17/08/2005') } } })
  • V8 JavaScript engine ECMAscript V8 JavaScript Engine standardized JSON strict mode
  • Installation (Debian) & shell
  • Installation $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 $ echo 'deb http://downloadsdistro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list $ sudo apt-get update $ sudo apt-get install mongodb-10gen $ sudo /etc/init.d/mongodb {status|start|stop|restart| reload|force-reload}
  • Installation $ mongo MongoDB shell version 2.4.9 connection to : test > show databases default 0.203125GB test 0.203125GB local 0.078125GB reseau 0.203125GB > use reseau switched to db reseau > show collections network system.indexes traffic > db.traffic.count() 8
  • MongoDB – Drivers Client libraries ● ● ● ● ● ● ● ● ● ● ● ● ● C C++ C# Go Erlang Java JavaScript Node.js Perl PHP Python Ruby Scala Community Supported Drivers ● ● ● ● ● ● ● ● ● ● ● ● ● ● ActionScript3 ColdFusion D Dart Delphi Groovy Lips Lua Objective C Ocaml Opa PowerShell R Smalltalk http://docs.mongodb.org/ecosystem/drivers/
  • PHP - installation $ $ $ $ sudo sudo sudo sudo apt-get update apt-get install php5-dev pecl install mongo php5enmod mongo
  • Client PHP
  • PHP – classes & types ● MongoClient ● MongoId ● MongoDB ● MongoCode ● MongoCollection ● MongoDate ● MongoCursor ● MongoRegex ● MongoBinData ● MongoInt32 ● MongoInt64 ● MongoDBRef ● MongoGridFS ● MongoMinKey ● MongoGridFSFile ● MongoMaxKey ● MongoGridFSCursor ● MongoTimestamp
  • PHP – examples Create <?php $someDoc = [ 'author' 'content' 'nbComment' 'dateCreated' ]; => => => => 'ekino', 'mongod', 5, new MongoDate() $client = new MongoClient("mongodb://localhost/"); $database = $client->demoDb; $collection = $database->demoCollection; $collection->insert($someDoc); echo (string) $someDoc['_id']; // 52af1a617e0b18d9448b4567
  • PHP – examples $ mongo MongoDB shell version: 2.4.8 connecting to: test > show databases demoDb 0.203125GB local 0.078125GB > use demoDb switched to db demoDb > db.demoCollection.find(); { "_id" : ObjectId("52af1a617e0b18d9448b4567"), "author" : "ekino", "content" : "mongod", "nbComment" : 5, "dateCreated" : ISODate("2013-12-16T15:21:05.212Z") } > exit Bye $ php -r 'var_dump(date("Y-m-d H:i:s", hexdec("52af1a61")));' string(19) "2013-12-16 16:21:05"
  • Installation $ ls -lGh /var/lib/mongodb drwxr-xr-x 2 mongodb 4,0K déc. -rw------- 1 mongodb 64M déc. -rw------- 1 mongodb 16M déc. -rwxr-xr-x 1 mongodb 5 déc. drwxr-xr-x 2 mongodb 4,0K déc. 16 16 16 16 16 16:21 10:10 10:10 10:10 16:21 journal local.0 local.ns mongod.lock _tmp
  • PHP – examples $ ls -lGh /var/lib/mongodb -rw------- 1 mongodb 64M déc. -rw------- 1 mongodb 128M déc. -rw------- 1 mongodb 16M déc. drwxr-xr-x 2 mongodb 4,0K déc. -rw------- 1 mongodb 64M déc. -rw------- 1 mongodb 16M déc. -rwxr-xr-x 1 mongodb 5 déc. drwxr-xr-x 2 mongodb 4,0K déc. 16 16 16 16 16 16 16 16 16:21 16:21 16:21 16:21 10:10 10:10 10:10 16:21 demoDb.0 demoDb.1 demoDb.ns journal local.0 local.ns mongod.lock _tmp
  • PHP – examples Retrieve <?php $client = new MongoClient("mongodb://localhost/"); $database = $client->demoDb; $collection = $database->demoCollection; $collection->findOne(['nbComment' => ['$gt' => 3]]; $cursor = $collection->find(); $cursor->count(); // number of documents $cursor = $cursor->sort(['author' => 1]); $cursor = $cursor->limit(10); foreach ($cursor as $demo) { // iterator ... }
  • PHP – examples Update <?php $client = new MongoClient("mongodb://localhost/"); $database = $client->demoDb; $collection = $database->demoCollection; $query = ["author" => "ekino"]; $newdata = [ '$set' => [ "keywords" => "excellent ta_vu" ] ]; $options = [ 'upsert' => true, 'multiple' => false, 'j' => false // or fsync ]; $collection->update($query, $newdata, $options);
  • PHP – examples Delete <?php $client = new MongoClient("mongodb://localhost/"); $database = $client->demoDb; $collection = $database->demoCollection; $options = ["justOne" => true, "j" => false]; $collection->remove(['author' => 'ekino'], $options);
  • Administration
  • Package components ● mongod : primary daemon process for the MongoDB system ● mongos : routing service for MongoDB shard ● mongo : interactive JavaScript shell interface ● mongodump : creating a binary export ● mongorestore : writes data from a binary database dump ● ● mongostat : provides a quick overview of the status similar vmstat mongoperf : check disk I/O performance independently of MongoDB
  • Replication
  • Sharding
  • Tools
  • Interface - metric MMS - 10gen
  • Interface - GUI Robomongo https://github.com/paralect/robomongo
  • Conclusion
  • Intégration
  • Intégration SQL et/ou NoSQL ? Source : http://www.commitstrip.com/en/2012/04/10/what-do-you-mean-its-oversized/
  • Annexes Pool-DBM : PHP Library to create relationships between DBMS. Work with Doctrine Library. https://github.com/pokap/pool-dbm Source images : http://askdba.org/weblog/images/technical/nosql http://www.generation-trafic.fr/wp-content/uploads/2012/07/geolocalisation.jpg http://www.kchodorow.com/blog/wp-content/uploads/2010/03/sharding.png http://www.commitstrip.com/en/2012/04/10/what-do-you-mean-its-oversized/ http://www.pixelboy.fr/wp-content/uploads/2011/11/Firefox1.png http://robomongo.org/ http://nyccto.files.wordpress.com/2011/03/mysql_to_mongodb.gif http://www.elektronique.fr/cours/porte-logique/images/porte-logique-et.png