Upgrade to Pro — share decks privately, control downloads, hide ads and more …

nosql_presentation.pdf

Jacob Chencha
September 01, 2015

 nosql_presentation.pdf

Discussion on how NoSQL databases can be exploited to make your PHP application more awesome

Jacob Chencha

September 01, 2015
Tweet

More Decks by Jacob Chencha

Other Decks in Programming

Transcript

  1. Faster Development WHY NOSQL Faster Development Impedance Mismatch: The difference

    between the relational model and the in-memory datastructure 3
  2. Scaling WHY NOSQL Scaling Its cheaper to scale horizontally than

    vertically NoSQL databases run well on clusters. 4
  3. CAP theorem WHY NOSQL CAP theorem Also known as Brewer’s

    Conjucture Given the three properties of Consistency, Availability and Partition tolerance you can only get two. • Consistency: All accesses are seen by all parallel processes (or nodes, processors etc.) in the same order (sequentially) • Availability: Means that if you can talk to a node in the cluster, it can read and write data • Partition tolerance: Cluster can survive communication breakages in the cluster that separate the cluster into two partitions unable to communicate with each other. 6
  4. MongoDB WHY NOSQL MongoDB • Document oriented database • Documentation

    for mongo https://docs.mongodb.org/manual/ • Quick start for mongo shell http://docs.mongodb.org/getting-started/ shell/ • PHP extension http://php.net/manual/en/mongo.installation.php • Laravel Eloquent Library https://github.com/jenssegers/laravel-mongodb 8
  5. MongoDB WHY NOSQL Sample write <?php $m= new \MongoClient(); $db=$m->selectDb("sports");

    $db->history->insert(["year":2015,"score":50]); Sample read <?php $m= new MongoClient(); $db=$m->selectDb("sports"); $data=$db->history->find(["year"=> [ $exists =>true]]); 9
  6. Cassandra WHY NOSQL Cassandra • Column family datastore • Documentation

    for cassandra http://docs.datastax.com/en/getting_ started/doc/getting_started/intro.html • Quick start http://www.tutorialspoint.com/cassandra/cassandra_shell_ commands.htm • PHP extension https://github.com/datastax/php-driver Sample write <?php $cluster = Cassandra::cluster() ->build(); $keyspace = sports ; $session = $cluster->connect($keyspace); $statement = $session->execute(new Cassandra\SimpleStatement( "INSERT INTO scores (year, score) VALUES (2015, 50)" )); 10
  7. Cassandra WHY NOSQL Sample read <?php $cluster = Cassandra::cluster() ->build();

    $keyspace = sports ; $session = $cluster->connect($keyspace); $result = $session->execute(new Cassandra\SimpleStatement ("SELECT year, score FROM sports.scores")); var_dump($result); 11
  8. Neo4j WHY NOSQL Neo4j • Graph oriented database • Documentation

    http://neo4j.com/developer/get-started/ • Quick start. Neo4j comes with a web interface accessible from http://127.0.0.1:7474/ when installed. http://neo4j.com/docs/stable/ server-installation.html • Provides a REST interface • Wrapper provided by Josh Adell https://github.com/jadell/neo4jphp Create a Node <?php \\Source https://github.com/jadell/neo4jphp/wiki/Nodes-and-Relationships $arthur = $client->makeNode(); $arthur->setProperty( name , Arthur Dent ) ->setProperty( mood , nervous ) ->setProperty( home , small cottage ) ->save(); 12
  9. Neo4j WHY NOSQL $ford = $client->makeNode(); $ford->setProperty( name , Ford

    Prefect ) ->setProperty( occupation , travel writer ) ->save(); $arthurId = $arthur->getId(); Retreive a node $character = $client->getNode($arthurId); foreach ($character->getProperties() as $key => $value) { echo "$key: $value\n"; } // prints: // name: Arthur Dent // mood: nervous // home: small cottage $character->removeProperty( mood ) ->setProperty( home , demolished ) ->save(); foreach ($character->getProperties() as $key => $value) { echo "$key: $value\n"; } // prints: // name: Arthur Dent // home: demolished 13