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

What's hot (20)

PPT
jQuery Datatables With MongDb
sliimohara
 
PPTX
Introduzione a C#
Lorenz Cuno Klopfenstein
 
PDF
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
PDF
FrozenRails Training
Mike Dirolf
 
PPTX
Developing 2D Games with Stage3D
Mike Jones
 
PDF
言語の設計判断
nishio
 
PDF
MySQL Create Table
Hoyoung Jung
 
PDF
Зависимые типы в GHC 8. Максим Талдыкин
Юрий Сыровецкий
 
TXT
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Arian Gutierrez
 
PDF
コミュニケーションとしてのコード
Atsushi Shibata
 
TXT
Litebox
meli media
 
PDF
Making Mongo realtime - oplog tailing in Meteor
yaliceme
 
PDF
Couchdb
Brian Smith
 
TXT
R code
Manav Goel
 
KEY
Core dev summit
Jeff Miccolis
 
PPTX
Windows Server 2012 Active Directory Recovery
Serhad MAKBULOĞLU, MBA
 
KEY
MongoDB: How it Works
Mike Dirolf
 
PPT
Full-Stack JavaScript with Node.js
Michael Lehmann
 
PPTX
Super Advanced Python –act1
Ke Wei Louis
 
PPTX
Python queue solution with asyncio and kafka
Ondřej Veselý
 
jQuery Datatables With MongDb
sliimohara
 
Introduzione a C#
Lorenz Cuno Klopfenstein
 
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
FrozenRails Training
Mike Dirolf
 
Developing 2D Games with Stage3D
Mike Jones
 
言語の設計判断
nishio
 
MySQL Create Table
Hoyoung Jung
 
Зависимые типы в GHC 8. Максим Талдыкин
Юрий Сыровецкий
 
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Arian Gutierrez
 
コミュニケーションとしてのコード
Atsushi Shibata
 
Litebox
meli media
 
Making Mongo realtime - oplog tailing in Meteor
yaliceme
 
Couchdb
Brian Smith
 
R code
Manav Goel
 
Core dev summit
Jeff Miccolis
 
Windows Server 2012 Active Directory Recovery
Serhad MAKBULOĞLU, MBA
 
MongoDB: How it Works
Mike Dirolf
 
Full-Stack JavaScript with Node.js
Michael Lehmann
 
Super Advanced Python –act1
Ke Wei Louis
 
Python queue solution with asyncio and kafka
Ondřej Veselý
 

Viewers also liked (18)

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

Similar to MongoUK - PHP Development (20)

PDF
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
PDF
PHP Loves MongoDB - Dublin MUG (by Hannes)
Mark Hillick
 
PDF
How to use MongoDB with CakePHP
ichikaway
 
PDF
Back to Basics 2017: Mí primera aplicación MongoDB
MongoDB
 
PDF
视觉中国的MongoDB应用实践(QConBeijing2011)
Night Sailer
 
PDF
MongoDB开发应用实践
iammutex
 
KEY
MongoDB, PHP and the cloud - php cloud summit 2011
Steven Francia
 
PDF
MongoDB: a gentle, friendly overview
Antonio Pintus
 
KEY
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 
KEY
PostgreSQLからMongoDBへ
Basuke Suzuki
 
PDF
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
KEY
MongoDB
Steven Francia
 
PDF
MongoDB.pdf
KuldeepKumar778733
 
KEY
Mongo NYC PHP Development
Fitz Agard
 
PDF
MongoDB FabLab León
Juan Antonio Roy Couto
 
PDF
Introduction to MongoDB
Mike Dirolf
 
PDF
Philadelphia MongoDB User Group - Your First MongoDB Application
Michael Lynn
 
KEY
MongoDB Administration 20110922
radiocats
 
PPTX
Introduction to MongoDB
MongoDB
 
PDF
From SQL to MongoDB
Nuxeo
 
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
PHP Loves MongoDB - Dublin MUG (by Hannes)
Mark Hillick
 
How to use MongoDB with CakePHP
ichikaway
 
Back to Basics 2017: Mí primera aplicación MongoDB
MongoDB
 
视觉中国的MongoDB应用实践(QConBeijing2011)
Night Sailer
 
MongoDB开发应用实践
iammutex
 
MongoDB, PHP and the cloud - php cloud summit 2011
Steven Francia
 
MongoDB: a gentle, friendly overview
Antonio Pintus
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 
PostgreSQLからMongoDBへ
Basuke Suzuki
 
Mongo Presentation by Metatagg Solutions
Metatagg Solutions
 
MongoDB.pdf
KuldeepKumar778733
 
Mongo NYC PHP Development
Fitz Agard
 
MongoDB FabLab León
Juan Antonio Roy Couto
 
Introduction to MongoDB
Mike Dirolf
 
Philadelphia MongoDB User Group - Your First MongoDB Application
Michael Lynn
 
MongoDB Administration 20110922
radiocats
 
Introduction to MongoDB
MongoDB
 
From SQL to MongoDB
Nuxeo
 
Ad

More from Boxed Ice (7)

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

Recently uploaded (20)

PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
July Patch Tuesday
Ivanti
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
July Patch Tuesday
Ivanti
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Advancing WebDriver BiDi support in WebKit
Igalia
 

MongoUK - PHP Development

  • 1. PHP Development David Mytton 1/24 [email protected] / @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 [email protected] / @davidmytton