SlideShare a Scribd company logo
PHP Development




                 David Mytton
1/24   david@boxedice.com / @davidmytton
Server Density Monitoring


       Processing       Database            UI




2/24
                    www.serverdensity.com
13 months ago




3/24
       Why we moved: http://bit.ly/mysqltomongo
1. Install


       pecl install mongo




4/24
2. Connect


       $mongo =
       new Mongo(‘a.example.com,b.example.com’,
                  array('persist' => ''));




5/24
2. Connect


       mongodb://[username:password@]host1
       [:port1][,host2[:port2:],...]/db




6/24
Replica Pairs


       $mongo =
       new Mongo(‘a.example.com,b.example.com’,
                  array('persist' => ''));




7/24
Replica Pairs = Failover
                       Replica Pair




            Master A                    Slave A
             DC1                         DC2
           16GB RAM                   16GB RAM


                       Replica Pair




            Master B                    Slave B
             DC1                         DC2
8/24       16GB RAM                   16GB RAM
Persistent Connections


       $mongo =
       new Mongo(‘a.example.com,b.example.com’,
                  array('persist' => ''));




9/24
Persistent Connections


        $mongo =
        new Mongo(‘a.example.com,b.example.com’,
                   array('persist' => 'owl'));




10/24
db.stats()
        Documents                  937,393,315

        Collections                      27,566

        Indexes                          45,277

        Stored data                      638GB

        Inserts                    5000-8000/s


11/24
                  As of 17th Jun 2010.
3. Query


        $serversCollection = $mongo->selectCollection(‘servers’);

        $server = $serversCollection->findOne(array(‘os’ =>
        ‘windows’), array(‘_id’, ‘name’, ‘ip’));




12/24
3. Query


        $serversCollection = $mongo->selectCollection(‘servers’);

        $server = $serversCollection->findOne(array(‘os’ =>
        ‘windows’), array(‘_id’, ‘name’, ‘ip’));




13/24
3. Query


        $serversCollection = $mongo->selectCollection(‘servers’);

        $server = $serversCollection->findOne(array(‘os’ =>
        ‘windows’), array(‘_id’, ‘name’, ‘ip’));




14/24
Docs


        www.php.net/mongo




15/24
Abstraction/Map layers

                           •ActiveMongo
                           •Doctrine
                           •Mango
                           •Vork


        http://www.mongodb.org/display/DOCS/PHP+Language+Center

16/24
MongoDate

        MongoDB                           Equivalent
        new MongoDate()                       time()
        new MongoDate(strtotime(‘now’))       time()




17/24
MongoDate

 $from = new MongoDate(strtotime(‘2010-06-18 00:00:00’));
 $to = new MongoDate(strtotime(‘2010-06-18 23:59:59’));


 $collection->find(array(‘added’ => array('$gt' => $from,
 '$lte' => $to)));




18/24
MongoId

        $doc = $collection->findOne(array(‘_id’ =>
        ‘4b74ae0d064b35442948da4c’));




19/24
MongoId

        $id = new MongoId(‘4b74ae0d064b35442948da4c’);

        $doc = $collection->findOne(array(‘_id’ => $id));




20/24
MongoId & remove()
  Slow(er):
   $collection->remove(array(‘key1’ => 5, ‘key2’ => 6));

   Fast(er):
   $cursor = $collection->find(array(‘key1’ => 5, ‘key2’
   => 6));

   $while ($cursor->hasNext())
   {
     $item = $cursor->getNext();
     $key = new MongoId($cursor->key());
     $collection->remove(array('_id' => $key));
   }
21/24
Safe insert()

  $collection->insert($doc, array(‘safe’));




22/24
Docs


        www.php.net/mongo




23/24
Slides
          blog.boxedice.com/mongodb




                  David Mytton
24/24   david@boxedice.com / @davidmytton

More Related Content

PDF
MongoDB Oplog入門
PDF
MongoDBで作るソーシャルデータ新解析基盤
PDF
JavaSE7 Launch Event: Java7xGroovy
PDF
MongoDB全機能解説2
PDF
How to stand on the shoulders of giants
PDF
How to calculate the optimal undo retention in Oracle
PDF
20110514 mongo dbチューニング
PDF
ZeroMQ Is The Answer: DPC 11 Version
MongoDB Oplog入門
MongoDBで作るソーシャルデータ新解析基盤
JavaSE7 Launch Event: Java7xGroovy
MongoDB全機能解説2
How to stand on the shoulders of giants
How to calculate the optimal undo retention in Oracle
20110514 mongo dbチューニング
ZeroMQ Is The Answer: DPC 11 Version

What's hot (20)

PPT
jQuery Datatables With MongDb
PPTX
Introduzione a C#
PDF
Debugging: Rules And Tools - PHPTek 11 Version
PDF
FrozenRails Training
PPTX
Developing 2D Games with Stage3D
PDF
言語の設計判断
PDF
MySQL Create Table
PDF
Зависимые типы в GHC 8. Максим Талдыкин
TXT
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
PDF
コミュニケーションとしてのコード
TXT
Litebox
PDF
Making Mongo realtime - oplog tailing in Meteor
PDF
Couchdb
TXT
R code
KEY
Core dev summit
PPTX
Windows Server 2012 Active Directory Recovery
KEY
MongoDB: How it Works
PPT
Full-Stack JavaScript with Node.js
PPTX
Super Advanced Python –act1
PPTX
Python queue solution with asyncio and kafka
jQuery Datatables With MongDb
Introduzione a C#
Debugging: Rules And Tools - PHPTek 11 Version
FrozenRails Training
Developing 2D Games with Stage3D
言語の設計判断
MySQL Create Table
Зависимые типы в GHC 8. Максим Талдыкин
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
コミュニケーションとしてのコード
Litebox
Making Mongo realtime - oplog tailing in Meteor
Couchdb
R code
Core dev summit
Windows Server 2012 Active Directory Recovery
MongoDB: How it Works
Full-Stack JavaScript with Node.js
Super Advanced Python –act1
Python queue solution with asyncio and kafka
Ad

Viewers also liked (18)

PPTX
America Compared
PPTX
Latin America Slides
PPTX
California
PDF
Bvi Company Formation
PDF
Seychelles Company Formation
PPTX
The Little Ice Age
PDF
Belize Company Formation
PPT
Nations Report
PDF
Cyprus Trust Formation
PPTX
Investigación Acción
PPT
Nationsrpt 2&3
PDF
Cyprus Company Formation
PPTX
Script up your application with Lua! -- RyanE -- OpenWest 2014
PPT
1.4 Complete A Grid
PDF
MongoDB - Monitoring & queueing
PPT
Crossroads Of Freedom
PPSX
Presentación protocolo de investigación
PDF
Webinar - Approaching 1 billion documents with MongoDB
America Compared
Latin America Slides
California
Bvi Company Formation
Seychelles Company Formation
The Little Ice Age
Belize Company Formation
Nations Report
Cyprus Trust Formation
Investigación Acción
Nationsrpt 2&3
Cyprus Company Formation
Script up your application with Lua! -- RyanE -- OpenWest 2014
1.4 Complete A Grid
MongoDB - Monitoring & queueing
Crossroads Of Freedom
Presentación protocolo de investigación
Webinar - Approaching 1 billion documents with MongoDB
Ad

Similar to MongoUK - PHP Development (20)

KEY
Spl Not A Bridge Too Far phpNW09
PDF
From mysql to MongoDB(MongoDB2011北京交流会)
KEY
Can't Miss Features of PHP 5.3 and 5.4
PPT
Mongo-Drupal
PPTX
MiamiJS - The Future of JavaScript
ODP
This upload requires better support for ODP format
KEY
Talkaboutlithium
PDF
mongodb-introduction
KEY
PHP Development With MongoDB
KEY
PHP Development with MongoDB (Fitz Agard)
PDF
PHP Data Objects
PDF
Refactoring to Macros with Clojure
PDF
4069180 Caching Performance Lessons From Facebook
PDF
Being functional in PHP (PHPDay Italy 2016)
KEY
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
PDF
Doctrine MongoDB Object Document Mapper
PPTX
Getting Started with MongoDB and NodeJS
PPTX
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
PDF
Latinoware
PDF
Php tips-and-tricks4128
Spl Not A Bridge Too Far phpNW09
From mysql to MongoDB(MongoDB2011北京交流会)
Can't Miss Features of PHP 5.3 and 5.4
Mongo-Drupal
MiamiJS - The Future of JavaScript
This upload requires better support for ODP format
Talkaboutlithium
mongodb-introduction
PHP Development With MongoDB
PHP Development with MongoDB (Fitz Agard)
PHP Data Objects
Refactoring to Macros with Clojure
4069180 Caching Performance Lessons From Facebook
Being functional in PHP (PHPDay Italy 2016)
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Doctrine MongoDB Object Document Mapper
Getting Started with MongoDB and NodeJS
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Latinoware
Php tips-and-tricks4128

More from Boxed Ice (7)

PDF
MongoDB Tokyo - Monitoring and Queueing
PDF
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
PDF
MongoDB - Monitoring and queueing
PDF
Monitoring MongoDB (MongoUK)
PDF
Monitoring MongoDB (MongoSV)
PDF
MongoUK - PHP Development
PDF
MongoUK - Approaching 1 billion documents with MongoDB1 Billion Documents
MongoDB Tokyo - Monitoring and Queueing
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoDB - Monitoring and queueing
Monitoring MongoDB (MongoUK)
Monitoring MongoDB (MongoSV)
MongoUK - PHP Development
MongoUK - Approaching 1 billion documents with MongoDB1 Billion Documents

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Modernizing your data center with Dell and AMD
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction

MongoUK - PHP Development

  • 1. PHP Development David Mytton 1/24 david@boxedice.com / @davidmytton
  • 2. Server Density Monitoring Processing Database UI 2/24 www.serverdensity.com
  • 3. 13 months ago 3/24 Why we moved: http://bit.ly/mysqltomongo
  • 4. 1. Install pecl install mongo 4/24
  • 5. 2. Connect $mongo = new Mongo(‘a.example.com,b.example.com’, array('persist' => '')); 5/24
  • 6. 2. Connect mongodb://[username:password@]host1 [:port1][,host2[:port2:],...]/db 6/24
  • 7. Replica Pairs $mongo = new Mongo(‘a.example.com,b.example.com’, array('persist' => '')); 7/24
  • 8. Replica Pairs = Failover Replica Pair Master A Slave A DC1 DC2 16GB RAM 16GB RAM Replica Pair Master B Slave B DC1 DC2 8/24 16GB RAM 16GB RAM
  • 9. Persistent Connections $mongo = new Mongo(‘a.example.com,b.example.com’, array('persist' => '')); 9/24
  • 10. Persistent Connections $mongo = new Mongo(‘a.example.com,b.example.com’, array('persist' => 'owl')); 10/24
  • 11. db.stats() Documents 937,393,315 Collections 27,566 Indexes 45,277 Stored data 638GB Inserts 5000-8000/s 11/24 As of 17th Jun 2010.
  • 12. 3. Query $serversCollection = $mongo->selectCollection(‘servers’); $server = $serversCollection->findOne(array(‘os’ => ‘windows’), array(‘_id’, ‘name’, ‘ip’)); 12/24
  • 13. 3. Query $serversCollection = $mongo->selectCollection(‘servers’); $server = $serversCollection->findOne(array(‘os’ => ‘windows’), array(‘_id’, ‘name’, ‘ip’)); 13/24
  • 14. 3. Query $serversCollection = $mongo->selectCollection(‘servers’); $server = $serversCollection->findOne(array(‘os’ => ‘windows’), array(‘_id’, ‘name’, ‘ip’)); 14/24
  • 15. Docs www.php.net/mongo 15/24
  • 16. Abstraction/Map layers •ActiveMongo •Doctrine •Mango •Vork http://www.mongodb.org/display/DOCS/PHP+Language+Center 16/24
  • 17. MongoDate MongoDB Equivalent new MongoDate() time() new MongoDate(strtotime(‘now’)) time() 17/24
  • 18. MongoDate $from = new MongoDate(strtotime(‘2010-06-18 00:00:00’)); $to = new MongoDate(strtotime(‘2010-06-18 23:59:59’)); $collection->find(array(‘added’ => array('$gt' => $from, '$lte' => $to))); 18/24
  • 19. MongoId $doc = $collection->findOne(array(‘_id’ => ‘4b74ae0d064b35442948da4c’)); 19/24
  • 20. MongoId $id = new MongoId(‘4b74ae0d064b35442948da4c’); $doc = $collection->findOne(array(‘_id’ => $id)); 20/24
  • 21. MongoId & remove() Slow(er): $collection->remove(array(‘key1’ => 5, ‘key2’ => 6)); Fast(er): $cursor = $collection->find(array(‘key1’ => 5, ‘key2’ => 6)); $while ($cursor->hasNext()) { $item = $cursor->getNext(); $key = new MongoId($cursor->key()); $collection->remove(array('_id' => $key)); } 21/24
  • 22. Safe insert() $collection->insert($doc, array(‘safe’)); 22/24
  • 23. Docs www.php.net/mongo 23/24
  • 24. Slides blog.boxedice.com/mongodb David Mytton 24/24 david@boxedice.com / @davidmytton