Zend Course Catalog - PHP Web Application Server - PHP Development
MongoUK - PHP Development
-
Upload
boxed-ice -
Category
Technology
-
view
4.140 -
download
0
description
Transcript of MongoUK - PHP Development
PHP Development
David [email protected] / @davidmytton1/24
Server Density Monitoring
Processing Database UI
www.serverdensity.com2/24
13 months ago
Why we moved: http://bit.ly/mysqltomongo3/24
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
Master ADC1
16GB RAM
Slave ADC2
16GB RAM
Replica Pair
Master BDC1
16GB RAM
Slave BDC2
16GB RAM
Replica Pair
8/24
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
As of 17th Jun 2010.11/24
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
http://www.mongodb.org/display/DOCS/PHP+Language+Center
•ActiveMongo •Doctrine•Mango•Vork
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