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
MySQL Create Table
Hoyoung Jung
 
PDF
言語の設計判断
nishio
 
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
Python queue solution with asyncio and kafka
Ondřej Veselý
 
PPTX
Super Advanced Python –act1
Ke Wei Louis
 
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
 
MySQL Create Table
Hoyoung Jung
 
言語の設計判断
nishio
 
Зависимые типы в 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
 
Python queue solution with asyncio and kafka
Ondřej Veselý
 
Super Advanced Python –act1
Ke Wei Louis
 

Viewers also liked (7)

PDF
Monitoring MongoDB (MongoUK)
Boxed Ice
 
PDF
MongoDB - Monitoring and queueing
Boxed Ice
 
PDF
Monitoring MongoDB (MongoSV)
Boxed Ice
 
PDF
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Boxed Ice
 
PDF
Playing in Tune: How We Refactored Cube to Terabyte Scale
MongoDB
 
PDF
mongoDB Performance
Moshe Kaplan
 
PDF
MongoDB Tokyo - Monitoring and Queueing
Boxed Ice
 
Monitoring MongoDB (MongoUK)
Boxed Ice
 
MongoDB - Monitoring and queueing
Boxed Ice
 
Monitoring MongoDB (MongoSV)
Boxed Ice
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Boxed Ice
 
Playing in Tune: How We Refactored Cube to Terabyte Scale
MongoDB
 
mongoDB Performance
Moshe Kaplan
 
MongoDB Tokyo - Monitoring and Queueing
Boxed Ice
 
Ad

Similar to MongoUK - PHP Development (20)

KEY
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
 
PDF
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
KEY
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
PPT
Mongo-Drupal
Forest Mars
 
PPTX
MiamiJS - The Future of JavaScript
Caridy Patino
 
ODP
This upload requires better support for ODP format
Forest Mars
 
KEY
Talkaboutlithium
noppoman722
 
PDF
mongodb-introduction
Tse-Ching Ho
 
KEY
PHP Development with MongoDB (Fitz Agard)
MongoSF
 
KEY
PHP Development With MongoDB
Fitz Agard
 
PDF
PHP Data Objects
Wez Furlong
 
PDF
Refactoring to Macros with Clojure
Dmitry Buzdin
 
PDF
4069180 Caching Performance Lessons From Facebook
guoqing75
 
PDF
Being functional in PHP (PHPDay Italy 2016)
David de Boer
 
KEY
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
PDF
Doctrine MongoDB Object Document Mapper
Jonathan Wage
 
PPTX
Getting Started with MongoDB and NodeJS
MongoDB
 
PPTX
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
PDF
Latinoware
kchodorow
 
PDF
Php tips-and-tricks4128
PrinceGuru MS
 
Spl Not A Bridge Too Far phpNW09
Michelangelo van Dam
 
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
Mongo-Drupal
Forest Mars
 
MiamiJS - The Future of JavaScript
Caridy Patino
 
This upload requires better support for ODP format
Forest Mars
 
Talkaboutlithium
noppoman722
 
mongodb-introduction
Tse-Ching Ho
 
PHP Development with MongoDB (Fitz Agard)
MongoSF
 
PHP Development With MongoDB
Fitz Agard
 
PHP Data Objects
Wez Furlong
 
Refactoring to Macros with Clojure
Dmitry Buzdin
 
4069180 Caching Performance Lessons From Facebook
guoqing75
 
Being functional in PHP (PHPDay Italy 2016)
David de Boer
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
Doctrine MongoDB Object Document Mapper
Jonathan Wage
 
Getting Started with MongoDB and NodeJS
MongoDB
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Latinoware
kchodorow
 
Php tips-and-tricks4128
PrinceGuru MS
 
Ad

Recently uploaded (20)

PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 

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