SlideShare une entreprise Scribd logo
1  sur  76
Télécharger pour lire hors ligne
Tips of
CakePHP & MongoDB

         2011/9/4
      CakeFest2011
     Yasushi Ichikawa
I am
Yasushi Ichikawa
Ichi


@ichikaway
http://cake.eizoku.com/blog
Topic
 ● What's MongoDB?
 ● Using MongoDB with CakePHP

  ● Setup

  ● Usage

 ● Security

 ● Future




@ichikaway   http://cake.eizoku.com/blog/
MongoDB

NoSQL
Performance
Scalability
@ichikaway   http://cake.eizoku.com/blog/
Good for
 ● Social-Apps
 ● Calculation on distributed servers

  ● log analysis

 ● Questionnaire form




@ichikaway   http://cake.eizoku.com/blog/
Terms

             RDB                 MongoDB
             Table               Collection
             Row                 Document
         Column                      Field


@ichikaway     http://cake.eizoku.com/blog/
Schema free
             Posts Collection

                 id, title, body

              id, name, tel, fax

         id, name, nickname, email
                     Posts collection




@ichikaway   http://cake.eizoku.com/blog/
Schema free
    Screen
  Blog                           Blog collection

  Title xxxx                     Title : xxxx
  Text yyyy                      Text : yyyy
                     data        Tag: [tag1,tag2,tag3]
  tag1,tag2,tag3                 Comment:
                                  [
  Comment1                          comment1,
  Comment2                          comment2,
  Comment3                          comment3
                                  ]


@ichikaway     http://cake.eizoku.com/blog/
MongoDB operators
   Find operators
      $gt, $gte                     db.posts.find(
       $lt, $lte                      { age : { $gt: 5 }}
         $ne                        )
          $in
         $nin
         $or
http://www.mongodb.org/display/DOCS/Advanced+Queries


@ichikaway          http://cake.eizoku.com/blog/
MongoDB operators
 Update operators
       $inc                         db.posts.update(
      $set                            { name: “Ichi” },
     $push                            { $inc: { cnt: 1 }}
      $pull                         )
      $pop
     $unset
http://www.mongodb.org/display/DOCS/Updating


@ichikaway          http://cake.eizoku.com/blog/
Functions
 ● Geospatial index (location info)
 ● Map/Reduce

 ● Binary file saving (GridFS)

 ● Sharding

 ● etc




@ichikaway   http://cake.eizoku.com/blog/
WebSite
@ichikaway   http://cake.eizoku.com/blog/
http://kanael.net




@ichikaway    http://cake.eizoku.com/blog/
http://kanael.net




@ichikaway    http://cake.eizoku.com/blog/
kanael.net
 ●Server
  ● VPS(2.4GHz-2core, 1.5GMem) x 1

 ●Application

  ● 40% write, 60% read

  ● 300,000 ducuments




@ichikaway   http://cake.eizoku.com/blog/
kanael.net
 ● Peak traffic
  ● 100,000+ requests/day

  ● CPU 75% (MongoDB 10%)




@ichikaway   http://cake.eizoku.com/blog/
Topic
 ● What's MongoDB?
 ● Using MongoDB with CakePHP

  ● Setup

  ● Usage

 ● Security

 ● Future




@ichikaway   http://cake.eizoku.com/blog/
CakePHP MongoDB

Repository
github.com/ichikaway
/cakephp-mongodb/

@ichikaway   http://cake.eizoku.com/blog/
CakePHP MongoDB

Repository
●Test files
●API documents

●Sample Applications


@ichikaway   http://cake.eizoku.com/blog/
CakePHP MongoDB
   PHP5+
   CakePHP1.2, 1.3, 2.0-beta
   Pecl Mongo driver
   Documents
    ●   https://github.com/ichikaway/cakephp-
        mongodb/wiki

@ichikaway      http://cake.eizoku.com/blog/
Structure
                     Model

       CakePHP-MongoDB Datasource

                   MongoDB

               MongoCollection

                 MongoCursor

@ichikaway   http://cake.eizoku.com/blog/
Setup
@ichikaway   http://cake.eizoku.com/blog/
Setup pecl mongo
 pecl install mongo
 vi php.ini
 extension=mongo.so

@ichikaway   http://cake.eizoku.com/blog/
CakePHP1.3

@ichikaway   http://cake.eizoku.com/blog/
Setup Cake Mongo(1.3)

 cd app/plugins
 git clone
 git://github.com/ichikaway/cakephp-
 mongodb.git mongodb
 vi app/config/database.php

@ichikaway   http://cake.eizoku.com/blog/
database.php Cake1.3
 class DATABASE_CONFIG {
    public $default = array(
         'driver' => 'mongodb.mongodbSource',
         'database' => 'blog',
         'host' => 'localhost',
         'port' => 27017,
    );


@ichikaway      http://cake.eizoku.com/blog/
CakePHP2.0

@ichikaway   http://cake.eizoku.com/blog/
Setup Cake Mongo(2.0)
cd app/Plugin
git clone
git://github.com/ichikaway/cakephp-
mongodb.git Mongodb
git checkout -b cake2.0 origin/cake2.0
vi app/Config/database.php
@ichikaway   http://cake.eizoku.com/blog/
database.php Cake2.0
// app/Config/database.php
class DATABASE_CONFIG {
  public $default = array(
       'datasource' => 'Mongodb.MongodbSource',
       'host' => 'localhost',
       'database' => 'blog',
       'port' => 27017,
  );



@ichikaway         http://cake.eizoku.com/blog/
Load plugin Cake2.0

 //app/Config/bootstrap.php
 CakePlugin::load('Mongodb')




@ichikaway   http://cake.eizoku.com/blog/
Sample Post Model
 class Post extends AppModel
 {
    public $primaryKey = '_id';

 }



@ichikaway   http://cake.eizoku.com/blog/
Useage
@ichikaway   http://cake.eizoku.com/blog/
find data
 class PostsController extends AppController
 {
     public function index() {
         $this->Post->find('all', $options);
     }
 }                            fields, conditions,
                              order, limit



@ichikaway       http://cake.eizoku.com/blog/
Insert data
 $data = array('name' => 'Ichi'
                'age' => 32 );

 $this->Post->save($data);

      _id:xxx1, name: 'Ichi', 'age':32
                  Posts collection



@ichikaway   http://cake.eizoku.com/blog/
Update data
 $data = array( '_id'  => 'xxx1',
                'name' => 'Yasu' );
 $this->Post->save($data);
// in Cake-Mongo DataSource
$MongoCollection->update(
     array('_id' => 'xxx001'),
     array('$set' => array('name' => 'Yasu')),
);

@ichikaway   http://cake.eizoku.com/blog/
$set operator
 Without $set
      id:xxx1, name: 'Yasu'
                  Posts collection



 With $set
      id:xxx1, name: 'Yasu', 'age':32
                  Posts collection


@ichikaway   http://cake.eizoku.com/blog/
Use other
              update
             operators
@ichikaway    http://cake.eizoku.com/blog/
Update operator ($inc)
$data = array( '_id'    => 'xxx1',
                '$inc' => array('age' => 1) );
$this->Post->save($data);

    // in Cake-Mongo DataSource
    $MongoCollection->update(
         array('_id' => 'xxx001'),
         array('$inc' => array('age' => 1)),
    );
@ichikaway   http://cake.eizoku.com/blog/
Update operator(result)
      _id:xxx1, name: 'Ichi', 'age':32
                  Posts collection




      _id:xxx1, name: 'Ichi', 'age':33,
                   Posts collection



@ichikaway   http://cake.eizoku.com/blog/
Update operator(complex)
$data = array(
    '_id'   => 'xxx1',
    '$inc' => array('age' => 1),
    '$push' => array('tags' => array('php', 'mongo'))
);
$this->Post->save($data);




@ichikaway     http://cake.eizoku.com/blog/
Update operator(result)
      _id:xxx1, name: 'Ichi', 'age':32
                  Posts collection




      _id:xxx1, name: 'Ichi', 'age':33,
      tags: ['php', 'mongo']
                   Posts collection



@ichikaway   http://cake.eizoku.com/blog/
Update operator
 ●see Wiki
  ● https://github.com/ichikaway/cakephp-

    mongodb/wiki/How-to-use-MongoDB-update-
    operators

 ●   see test code
     ● testUpdate()

     ● testUpdateWithoutMongoSchemaProperty()




@ichikaway     http://cake.eizoku.com/blog/
Get
      Cake Mongo
      DataSource
        Object
@ichikaway   http://cake.eizoku.com/blog/
Source methods
 ●   ensureIndex()
 ●   mapreduce()
 ●   group()
  See wiki
  https://github.com/ichikaway/cakephp-mongodb/wiki/_pages

@ichikaway      http://cake.eizoku.com/blog/
ex. make index
 $ds = $this->Post->getDataSource();

 $ds->ensureIndex(
          $this->Post,
          array('title' => 1)
 );

@ichikaway    http://cake.eizoku.com/blog/
Get
 MongoDB Object

@ichikaway   http://cake.eizoku.com/blog/
MongoDB Object
 ●   CakeMongo DataSource
     ●   not support all functions of MongoDB
         – gridFs

         – DbRef




@ichikaway     http://cake.eizoku.com/blog/
get MongoDB Object
 $mongo =
   $this->Post->getMongoDb();




@ichikaway   http://cake.eizoku.com/blog/
get MongoDB Object
 $mongo->getGridFs();
 $mongo->setSlaveOkay();
 $mongo->createDbRef();

 See php manual
 http://php.net/manual/en/class.mongodb.php

@ichikaway   http://cake.eizoku.com/blog/
Get
 MongoCollection
     Object
@ichikaway   http://cake.eizoku.com/blog/
get Mongo Collection
 $mongo =
   $this->Model->getMongoDb();

 $collection = $mongo->
   selectCollection('posts');


@ichikaway   http://cake.eizoku.com/blog/
get Mongo Collection
 $collection->find();
 $collection->update();
 $collection->insert();
 $collection->createDbRef();

 See php manual
 http://php.net/manual/en/class.mongocollection.php

@ichikaway   http://cake.eizoku.com/blog/
Replica Sets


@ichikaway   http://cake.eizoku.com/blog/
Replica sets
●   master/slave replication
●   automatic failover
●   automatic recovery


@ichikaway   http://cake.eizoku.com/blog/
Replica sets
                       Replication
        Server1                       Server2
        Primary                      Secondary

    Replication



                                     Application
      Server3
                                       Server
     Secondary
                                     (CakePHP)



@ichikaway        http://cake.eizoku.com/blog/
Replica sets
                       Replication
        Server1                       Server2
        Primary                      Secondary

    Replication



                                     Application
      Server3
                                       Server
     Secondary
                                     (CakePHP)



@ichikaway        http://cake.eizoku.com/blog/
Replica sets
       Server1                  Server2
       Primary                  Primary

                 Replication



                               Application
      Server3
                                 Server
     Secondary
                               (CakePHP)



@ichikaway   http://cake.eizoku.com/blog/
database.php Cake1.3
class DATABASE_CONFIG {
  public $default = array(
       'driver' => 'mongodb.mongodbSource',
       'database' => 'blog',
       'replicaset' => array(
             'host' =>'mongodb://loginid:password@
                       Server1:27021,Server2:27022/blog',
             'options' => array('replicaSet' => 'myRepl')
          ),
  );

   https://github.com/ichikaway/cakephp-mongodb/wiki/How-to-connect-to-replicaset-servers


@ichikaway               http://cake.eizoku.com/blog/
Topic
 ● What's MongoDB?
 ● Using MongoDB with CakePHP

  ● Setup

  ● Usage

 ● Security

 ● Future




@ichikaway   http://cake.eizoku.com/blog/
Injection
              Attack

@ichikaway   http://cake.eizoku.com/blog/
ONLY
                PHP   ( ; ´Д ` )




@ichikaway   http://cake.eizoku.com/blog/
WHY??

@ichikaway   http://cake.eizoku.com/blog/
Injection Attack
         $user = $collection->find(array(
            "username" => $_GET['username'],
            "passwd" => $_GET['passwd']
         ));

●   PHP makes array data from GET/POST request
    ●
        ex.   login.php?username=admin&passwd[$ne]=1




@ichikaway           http://cake.eizoku.com/blog/
Injection Attack
         $user = $collection->find(array(
            "username" => $_GET['username'],
                           'admin',
            "passwd" => $_GET['passwd']
                           array("$ne" => 1)
         ));

●   PHP makes array data from GET/POST request
    ●
        ex.   login.php?username=admin&passwd[$ne]=1




@ichikaway           http://cake.eizoku.com/blog/
Solution
●
    Don't trust user input data
    ●   GET/POST/Cookie
●   Solution
    ●   Cast to string
    ●   Check all keys of array


@ichikaway       http://cake.eizoku.com/blog/
Solution


      Cast to string

@ichikaway   http://cake.eizoku.com/blog/
Solution(cast to string)

 $cursor = $collection->find(array(
    "username" => (string)$_GET['username'],
    "passwd" => (string)$_GET['passwd']
 ));




@ichikaway   http://cake.eizoku.com/blog/
Solution(cast to string)

 $cursor = $collection->find(array(
    "username" => 'admin',
    "passwd" => 'Array'
 ));




@ichikaway   http://cake.eizoku.com/blog/
Solution

       Check keys
           of
        input data
@ichikaway   http://cake.eizoku.com/blog/
Solution(check keys)


        SecurePHP
          Library
   https://github.com/ichikaway/SecurePHP
@ichikaway   http://cake.eizoku.com/blog/
SecurePHP
●
    Check Post/Get/Cookie
●   Check all array keys
    ●
        allow: a-z0-9:-_./
●   Check null byte
@ichikaway    http://cake.eizoku.com/blog/
SecurePHP
vi webroot/index.php

 require_once(
    'SecurePHP/config/bootstrap.php'
 );
 $Dispatcher = new Dispatcher();
 $Dispatcher->dispatch();

@ichikaway   http://cake.eizoku.com/blog/
Topic
 ● What's MongoDB?
 ● Using MongoDB with CakePHP

  ● Setup

  ● Usage

 ● Security

 ● Future




@ichikaway   http://cake.eizoku.com/blog/
In the future

 Relational data fetch
    coming soon
  (hasOne, hasMany, belongsTo)
             relation branch



@ichikaway   http://cake.eizoku.com/blog/
Summary
 ● What's MongoDB?
 ● Using MongoDB with CakePHP

  ● Setup

  ● Usage(find, save, MongoObject)

 ● Security

  ● Injection attack

 ● Future

  ● Relational data fetch



@ichikaway   http://cake.eizoku.com/blog/
THANK YOU


@ichikaway   http://cake.eizoku.com/blog/

Contenu connexe

Tendances

Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkG Woo
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201Fabien Potencier
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APISix Apart KK
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011camp_drupal_ua
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksNate Abele
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsPierre MARTIN
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.fRui Apps
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of LithiumNate Abele
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionNate Abele
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksBruno Rocha
 

Tendances (20)

Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
 

En vedette

Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)ichikaway
 
MongoDBアプリの実例
MongoDBアプリの実例MongoDBアプリの実例
MongoDBアプリの実例Kazuyuki Namba
 
Bakshanam kazhikkumpol orkkenda sunnathukal
Bakshanam kazhikkumpol orkkenda sunnathukal Bakshanam kazhikkumpol orkkenda sunnathukal
Bakshanam kazhikkumpol orkkenda sunnathukal shabeel pn
 
Trabajo ntics
Trabajo nticsTrabajo ntics
Trabajo nticsDiany Cr
 
torre de papel y carton
torre de papel y cartontorre de papel y carton
torre de papel y carton06121996
 
A representación da prostitución nos medios de comunicación galegos
A representación da prostitución nos medios de comunicación galegosA representación da prostitución nos medios de comunicación galegos
A representación da prostitución nos medios de comunicación galegosivanagusto
 
54 ozel
54 ozel54 ozel
54 ozeltmder
 
Geo Sol About Geo Thermal
Geo Sol  About Geo ThermalGeo Sol  About Geo Thermal
Geo Sol About Geo ThermalKnut Linke
 
Diari del 14 de maig de 2015
Diari del 14 de maig de 2015Diari del 14 de maig de 2015
Diari del 14 de maig de 2015diarimes
 
Las vitaminas presentacion
Las vitaminas presentacionLas vitaminas presentacion
Las vitaminas presentacionerik2892
 
noble praxis tipps - telefon- und webkonferenzen
noble praxis tipps - telefon- und webkonferenzennoble praxis tipps - telefon- und webkonferenzen
noble praxis tipps - telefon- und webkonferenzennoble kommunikation
 
Bitcoin meetup Paralelní Polis - O stavebních kamenech
Bitcoin meetup Paralelní Polis - O stavebních kamenechBitcoin meetup Paralelní Polis - O stavebních kamenech
Bitcoin meetup Paralelní Polis - O stavebních kamenechMartin Šíp
 
Dich web anh an 2
Dich web anh an 2Dich web anh an 2
Dich web anh an 2upa098
 
25 sayings grammar practice
25 sayings grammar practice25 sayings grammar practice
25 sayings grammar practiceBrett Vaden
 
Powerpoint coneixement del medi pablo blasco
Powerpoint coneixement del medi   pablo blascoPowerpoint coneixement del medi   pablo blasco
Powerpoint coneixement del medi pablo blascoPablo Blasco
 

En vedette (20)

Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)
 
MongoDBアプリの実例
MongoDBアプリの実例MongoDBアプリの実例
MongoDBアプリの実例
 
Bakshanam kazhikkumpol orkkenda sunnathukal
Bakshanam kazhikkumpol orkkenda sunnathukal Bakshanam kazhikkumpol orkkenda sunnathukal
Bakshanam kazhikkumpol orkkenda sunnathukal
 
Trabajo ntics
Trabajo nticsTrabajo ntics
Trabajo ntics
 
torre de papel y carton
torre de papel y cartontorre de papel y carton
torre de papel y carton
 
A representación da prostitución nos medios de comunicación galegos
A representación da prostitución nos medios de comunicación galegosA representación da prostitución nos medios de comunicación galegos
A representación da prostitución nos medios de comunicación galegos
 
La justicia
La justiciaLa justicia
La justicia
 
54 ozel
54 ozel54 ozel
54 ozel
 
Geo Sol About Geo Thermal
Geo Sol  About Geo ThermalGeo Sol  About Geo Thermal
Geo Sol About Geo Thermal
 
Diari del 14 de maig de 2015
Diari del 14 de maig de 2015Diari del 14 de maig de 2015
Diari del 14 de maig de 2015
 
Evaluacion y formulacion de proyectos
Evaluacion y formulacion de proyectosEvaluacion y formulacion de proyectos
Evaluacion y formulacion de proyectos
 
Biol mol medicina_2008
Biol mol medicina_2008Biol mol medicina_2008
Biol mol medicina_2008
 
Las vitaminas presentacion
Las vitaminas presentacionLas vitaminas presentacion
Las vitaminas presentacion
 
noble praxis tipps - telefon- und webkonferenzen
noble praxis tipps - telefon- und webkonferenzennoble praxis tipps - telefon- und webkonferenzen
noble praxis tipps - telefon- und webkonferenzen
 
Bitcoin meetup Paralelní Polis - O stavebních kamenech
Bitcoin meetup Paralelní Polis - O stavebních kamenechBitcoin meetup Paralelní Polis - O stavebních kamenech
Bitcoin meetup Paralelní Polis - O stavebních kamenech
 
Empresas ecológicas
Empresas ecológicasEmpresas ecológicas
Empresas ecológicas
 
Dich web anh an 2
Dich web anh an 2Dich web anh an 2
Dich web anh an 2
 
25 sayings grammar practice
25 sayings grammar practice25 sayings grammar practice
25 sayings grammar practice
 
Powerpoint coneixement del medi pablo blasco
Powerpoint coneixement del medi   pablo blascoPowerpoint coneixement del medi   pablo blasco
Powerpoint coneixement del medi pablo blasco
 
Book drive Flyer
Book drive FlyerBook drive Flyer
Book drive Flyer
 

Similaire à Tips for Using CakePHP and MongoDB

This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP formatForest Mars
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPichikaway
 
Talkaboutlithium
TalkaboutlithiumTalkaboutlithium
Talkaboutlithiumnoppoman722
 
A re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbaiA re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbaiPraveen Puglia
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To MocoNaoya Ito
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers StealBen Scofield
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018Adam Tomat
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちRyo Miyake
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?jaespinmora
 
Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8Ovadiah Myrgorod
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAEWinston Chen
 
Windows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureWindows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureMaarten Balliauw
 

Similaire à Tips for Using CakePHP and MongoDB (20)

This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHP
 
Talkaboutlithium
TalkaboutlithiumTalkaboutlithium
Talkaboutlithium
 
A re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbaiA re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbai
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Django crush course
Django crush course Django crush course
Django crush course
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?
 
Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAE
 
Windows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureWindows Azure Storage & Sql Azure
Windows Azure Storage & Sql Azure
 

Plus de ichikaway

forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編ichikaway
 
Understanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES EmulatorUnderstanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES Emulatorichikaway
 
VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話ichikaway
 
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019ichikaway
 
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019ichikaway
 
現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy 現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy ichikaway
 
OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料ichikaway
 
Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年ichikaway
 
VAaddyとは VAddyミートアップvol3_20160629
VAaddyとは  VAddyミートアップvol3_20160629VAaddyとは  VAddyミートアップvol3_20160629
VAaddyとは VAddyミートアップvol3_20160629ichikaway
 
脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015ichikaway
 
脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuoka脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuokaichikaway
 
Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!ichikaway
 
脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!ichikaway
 
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LTichikaway
 
継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2ichikaway
 
Ctf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dialCtf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dialichikaway
 
VAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuokaVAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuokaichikaway
 
Jenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテストJenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテストichikaway
 
継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料ichikaway
 
VAddy at LL Diver LT
VAddy at LL Diver LTVAddy at LL Diver LT
VAddy at LL Diver LTichikaway
 

Plus de ichikaway (20)

forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編
 
Understanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES EmulatorUnderstanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES Emulator
 
VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話
 
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
 
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
 
現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy 現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy
 
OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料
 
Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年
 
VAaddyとは VAddyミートアップvol3_20160629
VAaddyとは  VAddyミートアップvol3_20160629VAaddyとは  VAddyミートアップvol3_20160629
VAaddyとは VAddyミートアップvol3_20160629
 
脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015
 
脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuoka脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuoka
 
Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!
 
脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!
 
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
 
継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2
 
Ctf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dialCtf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dial
 
VAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuokaVAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuoka
 
Jenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテストJenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテスト
 
継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料
 
VAddy at LL Diver LT
VAddy at LL Diver LTVAddy at LL Diver LT
VAddy at LL Diver LT
 

Dernier

(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)oannq
 
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...JeylaisaManabat1
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxShubham Rawat
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 

Dernier (6)

(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)
 
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptx
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 

Tips for Using CakePHP and MongoDB

  • 1. Tips of CakePHP & MongoDB 2011/9/4 CakeFest2011 Yasushi Ichikawa
  • 3. Topic ● What's MongoDB? ● Using MongoDB with CakePHP ● Setup ● Usage ● Security ● Future @ichikaway http://cake.eizoku.com/blog/
  • 5. Good for ● Social-Apps ● Calculation on distributed servers ● log analysis ● Questionnaire form @ichikaway http://cake.eizoku.com/blog/
  • 6. Terms RDB MongoDB Table Collection Row Document Column Field @ichikaway http://cake.eizoku.com/blog/
  • 7. Schema free Posts Collection id, title, body id, name, tel, fax id, name, nickname, email Posts collection @ichikaway http://cake.eizoku.com/blog/
  • 8. Schema free Screen Blog Blog collection Title xxxx Title : xxxx Text yyyy Text : yyyy data Tag: [tag1,tag2,tag3] tag1,tag2,tag3 Comment: [ Comment1 comment1, Comment2 comment2, Comment3 comment3 ] @ichikaway http://cake.eizoku.com/blog/
  • 9. MongoDB operators Find operators $gt, $gte db.posts.find( $lt, $lte { age : { $gt: 5 }} $ne ) $in $nin $or http://www.mongodb.org/display/DOCS/Advanced+Queries @ichikaway http://cake.eizoku.com/blog/
  • 10. MongoDB operators Update operators $inc db.posts.update( $set { name: “Ichi” }, $push { $inc: { cnt: 1 }} $pull ) $pop $unset http://www.mongodb.org/display/DOCS/Updating @ichikaway http://cake.eizoku.com/blog/
  • 11. Functions ● Geospatial index (location info) ● Map/Reduce ● Binary file saving (GridFS) ● Sharding ● etc @ichikaway http://cake.eizoku.com/blog/
  • 12. WebSite @ichikaway http://cake.eizoku.com/blog/
  • 13. http://kanael.net @ichikaway http://cake.eizoku.com/blog/
  • 14. http://kanael.net @ichikaway http://cake.eizoku.com/blog/
  • 15. kanael.net ●Server ● VPS(2.4GHz-2core, 1.5GMem) x 1 ●Application ● 40% write, 60% read ● 300,000 ducuments @ichikaway http://cake.eizoku.com/blog/
  • 16. kanael.net ● Peak traffic ● 100,000+ requests/day ● CPU 75% (MongoDB 10%) @ichikaway http://cake.eizoku.com/blog/
  • 17. Topic ● What's MongoDB? ● Using MongoDB with CakePHP ● Setup ● Usage ● Security ● Future @ichikaway http://cake.eizoku.com/blog/
  • 19. CakePHP MongoDB Repository ●Test files ●API documents ●Sample Applications @ichikaway http://cake.eizoku.com/blog/
  • 20. CakePHP MongoDB  PHP5+  CakePHP1.2, 1.3, 2.0-beta  Pecl Mongo driver  Documents ● https://github.com/ichikaway/cakephp- mongodb/wiki @ichikaway http://cake.eizoku.com/blog/
  • 21. Structure Model CakePHP-MongoDB Datasource MongoDB MongoCollection MongoCursor @ichikaway http://cake.eizoku.com/blog/
  • 22. Setup @ichikaway http://cake.eizoku.com/blog/
  • 23. Setup pecl mongo pecl install mongo vi php.ini extension=mongo.so @ichikaway http://cake.eizoku.com/blog/
  • 24. CakePHP1.3 @ichikaway http://cake.eizoku.com/blog/
  • 25. Setup Cake Mongo(1.3) cd app/plugins git clone git://github.com/ichikaway/cakephp- mongodb.git mongodb vi app/config/database.php @ichikaway http://cake.eizoku.com/blog/
  • 26. database.php Cake1.3 class DATABASE_CONFIG { public $default = array( 'driver' => 'mongodb.mongodbSource', 'database' => 'blog', 'host' => 'localhost', 'port' => 27017, ); @ichikaway http://cake.eizoku.com/blog/
  • 27. CakePHP2.0 @ichikaway http://cake.eizoku.com/blog/
  • 28. Setup Cake Mongo(2.0) cd app/Plugin git clone git://github.com/ichikaway/cakephp- mongodb.git Mongodb git checkout -b cake2.0 origin/cake2.0 vi app/Config/database.php @ichikaway http://cake.eizoku.com/blog/
  • 29. database.php Cake2.0 // app/Config/database.php class DATABASE_CONFIG { public $default = array( 'datasource' => 'Mongodb.MongodbSource', 'host' => 'localhost', 'database' => 'blog', 'port' => 27017, ); @ichikaway http://cake.eizoku.com/blog/
  • 30. Load plugin Cake2.0 //app/Config/bootstrap.php CakePlugin::load('Mongodb') @ichikaway http://cake.eizoku.com/blog/
  • 31. Sample Post Model class Post extends AppModel { public $primaryKey = '_id'; } @ichikaway http://cake.eizoku.com/blog/
  • 32. Useage @ichikaway http://cake.eizoku.com/blog/
  • 33. find data class PostsController extends AppController { public function index() { $this->Post->find('all', $options); } } fields, conditions, order, limit @ichikaway http://cake.eizoku.com/blog/
  • 34. Insert data $data = array('name' => 'Ichi' 'age' => 32 ); $this->Post->save($data); _id:xxx1, name: 'Ichi', 'age':32 Posts collection @ichikaway http://cake.eizoku.com/blog/
  • 35. Update data $data = array( '_id' => 'xxx1', 'name' => 'Yasu' ); $this->Post->save($data); // in Cake-Mongo DataSource $MongoCollection->update( array('_id' => 'xxx001'), array('$set' => array('name' => 'Yasu')), ); @ichikaway http://cake.eizoku.com/blog/
  • 36. $set operator Without $set id:xxx1, name: 'Yasu' Posts collection With $set id:xxx1, name: 'Yasu', 'age':32 Posts collection @ichikaway http://cake.eizoku.com/blog/
  • 37. Use other update operators @ichikaway http://cake.eizoku.com/blog/
  • 38. Update operator ($inc) $data = array( '_id' => 'xxx1', '$inc' => array('age' => 1) ); $this->Post->save($data); // in Cake-Mongo DataSource $MongoCollection->update( array('_id' => 'xxx001'), array('$inc' => array('age' => 1)), ); @ichikaway http://cake.eizoku.com/blog/
  • 39. Update operator(result) _id:xxx1, name: 'Ichi', 'age':32 Posts collection _id:xxx1, name: 'Ichi', 'age':33, Posts collection @ichikaway http://cake.eizoku.com/blog/
  • 40. Update operator(complex) $data = array( '_id' => 'xxx1', '$inc' => array('age' => 1), '$push' => array('tags' => array('php', 'mongo')) ); $this->Post->save($data); @ichikaway http://cake.eizoku.com/blog/
  • 41. Update operator(result) _id:xxx1, name: 'Ichi', 'age':32 Posts collection _id:xxx1, name: 'Ichi', 'age':33, tags: ['php', 'mongo'] Posts collection @ichikaway http://cake.eizoku.com/blog/
  • 42. Update operator ●see Wiki ● https://github.com/ichikaway/cakephp- mongodb/wiki/How-to-use-MongoDB-update- operators ● see test code ● testUpdate() ● testUpdateWithoutMongoSchemaProperty() @ichikaway http://cake.eizoku.com/blog/
  • 43. Get Cake Mongo DataSource Object @ichikaway http://cake.eizoku.com/blog/
  • 44. Source methods ● ensureIndex() ● mapreduce() ● group() See wiki https://github.com/ichikaway/cakephp-mongodb/wiki/_pages @ichikaway http://cake.eizoku.com/blog/
  • 45. ex. make index $ds = $this->Post->getDataSource(); $ds->ensureIndex( $this->Post, array('title' => 1) ); @ichikaway http://cake.eizoku.com/blog/
  • 46. Get MongoDB Object @ichikaway http://cake.eizoku.com/blog/
  • 47. MongoDB Object ● CakeMongo DataSource ● not support all functions of MongoDB – gridFs – DbRef @ichikaway http://cake.eizoku.com/blog/
  • 48. get MongoDB Object $mongo = $this->Post->getMongoDb(); @ichikaway http://cake.eizoku.com/blog/
  • 49. get MongoDB Object $mongo->getGridFs(); $mongo->setSlaveOkay(); $mongo->createDbRef(); See php manual http://php.net/manual/en/class.mongodb.php @ichikaway http://cake.eizoku.com/blog/
  • 50. Get MongoCollection Object @ichikaway http://cake.eizoku.com/blog/
  • 51. get Mongo Collection $mongo = $this->Model->getMongoDb(); $collection = $mongo-> selectCollection('posts'); @ichikaway http://cake.eizoku.com/blog/
  • 52. get Mongo Collection $collection->find(); $collection->update(); $collection->insert(); $collection->createDbRef(); See php manual http://php.net/manual/en/class.mongocollection.php @ichikaway http://cake.eizoku.com/blog/
  • 53. Replica Sets @ichikaway http://cake.eizoku.com/blog/
  • 54. Replica sets ● master/slave replication ● automatic failover ● automatic recovery @ichikaway http://cake.eizoku.com/blog/
  • 55. Replica sets Replication Server1 Server2 Primary Secondary Replication Application Server3 Server Secondary (CakePHP) @ichikaway http://cake.eizoku.com/blog/
  • 56. Replica sets Replication Server1 Server2 Primary Secondary Replication Application Server3 Server Secondary (CakePHP) @ichikaway http://cake.eizoku.com/blog/
  • 57. Replica sets Server1 Server2 Primary Primary Replication Application Server3 Server Secondary (CakePHP) @ichikaway http://cake.eizoku.com/blog/
  • 58. database.php Cake1.3 class DATABASE_CONFIG { public $default = array( 'driver' => 'mongodb.mongodbSource', 'database' => 'blog', 'replicaset' => array( 'host' =>'mongodb://loginid:password@ Server1:27021,Server2:27022/blog', 'options' => array('replicaSet' => 'myRepl') ), ); https://github.com/ichikaway/cakephp-mongodb/wiki/How-to-connect-to-replicaset-servers @ichikaway http://cake.eizoku.com/blog/
  • 59. Topic ● What's MongoDB? ● Using MongoDB with CakePHP ● Setup ● Usage ● Security ● Future @ichikaway http://cake.eizoku.com/blog/
  • 60. Injection Attack @ichikaway http://cake.eizoku.com/blog/
  • 61. ONLY PHP ( ; ´Д ` ) @ichikaway http://cake.eizoku.com/blog/
  • 62. WHY?? @ichikaway http://cake.eizoku.com/blog/
  • 63. Injection Attack $user = $collection->find(array( "username" => $_GET['username'], "passwd" => $_GET['passwd'] )); ● PHP makes array data from GET/POST request ● ex. login.php?username=admin&passwd[$ne]=1 @ichikaway http://cake.eizoku.com/blog/
  • 64. Injection Attack $user = $collection->find(array( "username" => $_GET['username'], 'admin', "passwd" => $_GET['passwd'] array("$ne" => 1) )); ● PHP makes array data from GET/POST request ● ex. login.php?username=admin&passwd[$ne]=1 @ichikaway http://cake.eizoku.com/blog/
  • 65. Solution ● Don't trust user input data ● GET/POST/Cookie ● Solution ● Cast to string ● Check all keys of array @ichikaway http://cake.eizoku.com/blog/
  • 66. Solution Cast to string @ichikaway http://cake.eizoku.com/blog/
  • 67. Solution(cast to string) $cursor = $collection->find(array( "username" => (string)$_GET['username'], "passwd" => (string)$_GET['passwd'] )); @ichikaway http://cake.eizoku.com/blog/
  • 68. Solution(cast to string) $cursor = $collection->find(array( "username" => 'admin', "passwd" => 'Array' )); @ichikaway http://cake.eizoku.com/blog/
  • 69. Solution Check keys of input data @ichikaway http://cake.eizoku.com/blog/
  • 70. Solution(check keys) SecurePHP Library https://github.com/ichikaway/SecurePHP @ichikaway http://cake.eizoku.com/blog/
  • 71. SecurePHP ● Check Post/Get/Cookie ● Check all array keys ● allow: a-z0-9:-_./ ● Check null byte @ichikaway http://cake.eizoku.com/blog/
  • 72. SecurePHP vi webroot/index.php require_once( 'SecurePHP/config/bootstrap.php' ); $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(); @ichikaway http://cake.eizoku.com/blog/
  • 73. Topic ● What's MongoDB? ● Using MongoDB with CakePHP ● Setup ● Usage ● Security ● Future @ichikaway http://cake.eizoku.com/blog/
  • 74. In the future Relational data fetch coming soon (hasOne, hasMany, belongsTo) relation branch @ichikaway http://cake.eizoku.com/blog/
  • 75. Summary ● What's MongoDB? ● Using MongoDB with CakePHP ● Setup ● Usage(find, save, MongoObject) ● Security ● Injection attack ● Future ● Relational data fetch @ichikaway http://cake.eizoku.com/blog/
  • 76. THANK YOU @ichikaway http://cake.eizoku.com/blog/