CouchDB, PHPillow & PHP
Transcript of CouchDB, PHPillow & PHP
![Page 1: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/1.jpg)
CouchDB, PHPillow & PHP
Kore Nordmann <[email protected]>
November 18, 2009
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 2: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/2.jpg)
About me 2 / 35
I Kore Nordmann, <[email protected]>, <[email protected]>
I Long time PHP developer
I Regular speaker, author, etc.
I Studies computer science in DortmundI Active open source developer:
I eZ Components (Graph, WebDav, Document), Arbit,PHPUnit, Torii, PHPillow, KaForkL, Image 3D, WCV, ...
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 3: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/3.jpg)
Outline 3 / 35
Introduction
CouchDB
PHPillow
Views
QA
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 4: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/4.jpg)
CouchDB is paradigmn shift 4 / 35
I No tables, document based databaseI No relational consistency
I Who uses foreign keys anyways?
I “No” clustered consistency, eventual consistency
I This talk tells you, why this is perfect for web applications
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 5: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/5.jpg)
CouchDB is paradigmn shift 4 / 35
I No tables, document based databaseI No relational consistency
I Who uses foreign keys anyways?
I “No” clustered consistency, eventual consistency
I This talk tells you, why this is perfect for web applications
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 6: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/6.jpg)
CouchDB is paradigmn shift 4 / 35
I No tables, document based databaseI No relational consistency
I Who uses foreign keys anyways?
I “No” clustered consistency, eventual consistency
I This talk tells you, why this is perfect for web applications
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 7: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/7.jpg)
CouchDB is paradigmn shift 4 / 35
I No tables, document based databaseI No relational consistency
I Who uses foreign keys anyways?
I “No” clustered consistency, eventual consistency
I This talk tells you, why this is perfect for web applications
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 8: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/8.jpg)
CouchDB is paradigmn shift 4 / 35
I No tables, document based databaseI No relational consistency
I Who uses foreign keys anyways?
I “No” clustered consistency, eventual consistency
I This talk tells you, why this is perfect for web applications
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 9: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/9.jpg)
Wiki as an example application 5 / 35
I See what the paradigms mean for $applicationI Wiki as an exampleI Refactoring (table-less)I Handle concurrent edits (MVCC)I Clustered (eventual consistency)
I Other examplesI Classic ACL handling: http:
//kore-nordmann.de/blog/couchdb_a_use_case.htmlI Applications using CouchDB:
http://wiki.apache.org/couchdb/CouchDB_in_the_wild(CRM, POI database, issue tracker, social networks, blogs, ...)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 10: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/10.jpg)
Wiki as an example application 5 / 35
I See what the paradigms mean for $applicationI Wiki as an exampleI Refactoring (table-less)I Handle concurrent edits (MVCC)I Clustered (eventual consistency)
I Other examplesI Classic ACL handling: http:
//kore-nordmann.de/blog/couchdb_a_use_case.htmlI Applications using CouchDB:
http://wiki.apache.org/couchdb/CouchDB_in_the_wild(CRM, POI database, issue tracker, social networks, blogs, ...)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 11: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/11.jpg)
Wiki as an example application 5 / 35
I See what the paradigms mean for $applicationI Wiki as an exampleI Refactoring (table-less)I Handle concurrent edits (MVCC)I Clustered (eventual consistency)
I Other examplesI Classic ACL handling: http:
//kore-nordmann.de/blog/couchdb_a_use_case.htmlI Applications using CouchDB:
http://wiki.apache.org/couchdb/CouchDB_in_the_wild(CRM, POI database, issue tracker, social networks, blogs, ...)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 12: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/12.jpg)
Wiki as an example application 5 / 35
I See what the paradigms mean for $applicationI Wiki as an exampleI Refactoring (table-less)I Handle concurrent edits (MVCC)I Clustered (eventual consistency)
I Other examplesI Classic ACL handling: http:
//kore-nordmann.de/blog/couchdb_a_use_case.htmlI Applications using CouchDB:
http://wiki.apache.org/couchdb/CouchDB_in_the_wild(CRM, POI database, issue tracker, social networks, blogs, ...)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 13: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/13.jpg)
Wiki as an example application 5 / 35
I See what the paradigms mean for $applicationI Wiki as an exampleI Refactoring (table-less)I Handle concurrent edits (MVCC)I Clustered (eventual consistency)
I Other examplesI Classic ACL handling: http:
//kore-nordmann.de/blog/couchdb_a_use_case.htmlI Applications using CouchDB:
http://wiki.apache.org/couchdb/CouchDB_in_the_wild(CRM, POI database, issue tracker, social networks, blogs, ...)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 14: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/14.jpg)
Wiki as an example application 5 / 35
I See what the paradigms mean for $applicationI Wiki as an exampleI Refactoring (table-less)I Handle concurrent edits (MVCC)I Clustered (eventual consistency)
I Other examplesI Classic ACL handling: http:
//kore-nordmann.de/blog/couchdb_a_use_case.htmlI Applications using CouchDB:
http://wiki.apache.org/couchdb/CouchDB_in_the_wild(CRM, POI database, issue tracker, social networks, blogs, ...)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 15: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/15.jpg)
Outline 6 / 35
Introduction
CouchDB
PHPillow
Views
QA
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 16: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/16.jpg)
CouchDB 7 / 35
I Apache top-level project
I Queried and indexed using map-reduce
I Accessed using REST-ful HTTP
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 17: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/17.jpg)
CouchDB 7 / 35
I Apache top-level project
I Queried and indexed using map-reduce
I Accessed using REST-ful HTTP
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 18: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/18.jpg)
CouchDB 7 / 35
I Apache top-level project
I Queried and indexed using map-reduce
I Accessed using REST-ful HTTP
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 19: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/19.jpg)
CouchDB 7 / 35
I Apache top-level project
I Queried and indexed using map-reduce
I Accessed using REST-ful HTTP
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 20: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/20.jpg)
CouchDB 8 / 35
I Erlang/OTP virtualmachine, developed byEricsson
I Highly concurrent
I Scales nearly linearly withthe amount of CPUs
I High reliability (ninenines)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 21: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/21.jpg)
CouchDB 8 / 35
I Erlang/OTP virtualmachine, developed byEricsson
I Highly concurrent
I Scales nearly linearly withthe amount of CPUs
I High reliability (ninenines)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 22: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/22.jpg)
CouchDB 8 / 35
I Erlang/OTP virtualmachine, developed byEricsson
I Highly concurrent
I Scales nearly linearly withthe amount of CPUs
I High reliability (ninenines)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 23: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/23.jpg)
CouchDB 8 / 35
I Erlang/OTP virtualmachine, developed byEricsson
I Highly concurrent
I Scales nearly linearly withthe amount of CPUs
I High reliability (ninenines)
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 24: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/24.jpg)
Create a database 9 / 35
1 $ c u r l − i −X PUT ht tp :// l o c a l h o s t :5984/ i p c w i k i2
3 HTTP/1 .1 201 Created4 Se r v e r : CouchDB/0 . 1 0 . 0 ( E r l ang OTP/R13B)5 Loca t i on : h t tp : // l o c a l h o s t :5984/ i p c w i k i6 Date : F r i , 13 Nov 2009 14 : 07 : 57 GMT7 Content−Type : t e x t / p l a i n ; c h a r s e t=ut f−88 Content−Length : 129 Cache−Con t r o l : must−r e v a l i d a t e
10
11 {”ok ” : t r u e }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 25: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/25.jpg)
Create a wiki document 10 / 35
1 $ c u r l − i −X PUT ht tp :// l o c a l h o s t :5984/ i p c w i k i / S t a r t−−data ’{”name ” : ” S t a r t ” , ” t e x t ” : ” He l l o World ! ”} ’
2
3 HTTP/1 .1 201 Created4 Se r v e r : CouchDB/0 . 1 0 . 0 ( E r l ang OTP/R13B)5 Loca t i on : h t tp : // l o c a l h o s t :5984/ i p c w i k i / S t a r t6 Etag : ”1−6bfd4885b6c62bb5169a19d5a81927e3 ”7 Date : F r i , 13 Nov 2009 14 : 14 : 55 GMT8 Content−Type : t e x t / p l a i n ; c h a r s e t=ut f−89 Content−Length : 68
10 Cache−Con t r o l : must−r e v a l i d a t e11
12 {”ok ” : t rue , ” i d ” :” S t a r t ” ,” r e v ”:”1−6bfd4885b6c62bb5169a19d5a81927e3 ”}
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 26: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/26.jpg)
Get a wiki document back 11 / 35
1 $ c u r l − i −X GET ht tp :// l o c a l h o s t :5984/ i p c w i k i / S t a r t2
3 HTTP/1 .1 200 OK4 Se r v e r : CouchDB/0 . 1 0 . 0 ( E r l ang OTP/R13B)5 Etag : ”1−6bfd4885b6c62bb5169a19d5a81927e3 ”6 Date : F r i , 13 Nov 2009 14 : 15 : 48 GMT7 Content−Type : t e x t / p l a i n ; c h a r s e t=ut f−88 Content−Length : 979 Cache−Con t r o l : must−r e v a l i d a t e
10
11 {” i d ” :” S t a r t ” ,” r e v ”:”1−6bfd4885b6c62bb5169a19d5a81927e3 ” ,”name ” :” S t a r t ” ,”t e x t ” : ” He l l o World !”}
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 27: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/27.jpg)
Inter document links 12 / 35
I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:
I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)
I Solution depends on update-ratio
1 { ” type ” : ” w i k i ” ,2 ”name ” : ” S t a r t ” ,3 ” t e x t ” : ” . . . ” ,4 }5
6 { ” type ” : ” d i s c u s s i o n ” ,7 ” w i k i ” : ” w ik i−S t a r t ” ,8 ” t e x t ” : ” . . . ” ,9 ”comments ” : [
10 { ”comment ” : ” . . . ” } ,11 ] ,12 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 28: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/28.jpg)
Inter document links 12 / 35
I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:
I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)
I Solution depends on update-ratio
1 { ” type ” : ” w i k i ” ,2 ”name ” : ” S t a r t ” ,3 ” t e x t ” : ” . . . ” ,4 }5
6 { ” type ” : ” d i s c u s s i o n ” ,7 ” w i k i ” : ” w ik i−S t a r t ” ,8 ” t e x t ” : ” . . . ” ,9 ”comments ” : [
10 { ”comment ” : ” . . . ” } ,11 ] ,12 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 29: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/29.jpg)
Inter document links 12 / 35
I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:
I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)
I Solution depends on update-ratio
1 { ” type ” : ” w i k i ” ,2 ”name ” : ” S t a r t ” ,3 ” t e x t ” : ” . . . ” ,4 }5
6 { ” type ” : ” d i s c u s s i o n ” ,7 ” w i k i ” : ” w ik i−S t a r t ” ,8 ” t e x t ” : ” . . . ” ,9 ”comments ” : [
10 { ”comment ” : ” . . . ” } ,11 ] ,12 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 30: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/30.jpg)
Inter document links 12 / 35
I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:
I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)
I Solution depends on update-ratio
1 { ” type ” : ” w i k i ” ,2 ”name ” : ” S t a r t ” ,3 ” t e x t ” : ” . . . ” ,4 }5
6 { ” type ” : ” d i s c u s s i o n ” ,7 ” w i k i ” : ” w ik i−S t a r t ” ,8 ” t e x t ” : ” . . . ” ,9 ”comments ” : [
10 { ”comment ” : ” . . . ” } ,11 ] ,12 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 31: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/31.jpg)
Inter document links 12 / 35
I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:
I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)
I Solution depends on update-ratio
1 { ” type ” : ” w i k i ” ,2 ”name ” : ” S t a r t ” ,3 ” t e x t ” : ” . . . ” ,4 }5
6 { ” type ” : ” d i s c u s s i o n ” ,7 ” w i k i ” : ” w ik i−S t a r t ” ,8 ” t e x t ” : ” . . . ” ,9 ”comments ” : [
10 { ”comment ” : ” . . . ” } ,11 ] ,12 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 32: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/32.jpg)
Inter document links 12 / 35
I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:
I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)
I Solution depends on update-ratio
1 { ” type ” : ” w i k i ” ,2 ”name ” : ” S t a r t ” ,3 ” t e x t ” : ” . . . ” ,4 }5
6 { ” type ” : ” d i s c u s s i o n ” ,7 ” w i k i ” : ” w ik i−S t a r t ” ,8 ” t e x t ” : ” . . . ” ,9 ”comments ” : [
10 { ”comment ” : ” . . . ” } ,11 ] ,12 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 33: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/33.jpg)
Migration / Refactoring 13 / 35
I Change document structure at any time
I No need for non-transaction-safe DDL
I Fits rapid development approaches with common customerrequested changes to the data structure
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 34: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/34.jpg)
Migration / Refactoring 13 / 35
I Change document structure at any time
I No need for non-transaction-safe DDL
I Fits rapid development approaches with common customerrequested changes to the data structure
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 35: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/35.jpg)
Migration / Refactoring 13 / 35
I Change document structure at any time
I No need for non-transaction-safe DDL
I Fits rapid development approaches with common customerrequested changes to the data structure
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 36: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/36.jpg)
Local conflicts 14 / 35
I Updates and deletes need to use the revision ID
1 $ c u r l −X GET ht tp : // l o c a l h o s t :5984/ i p c w i k i / S t a r t2
3 {” i d ” :” S t a r t ” ,” r e v ”:”1−6bfd4885b6c62bb5169a19d5a81927e3 ” ,”name ” :” S t a r t” ,” t e x t ” : ” He l l o World !”}
4
5 $ c u r l − i −X DELETE ht tp :// l o c a l h o s t :5984/ i p c w i k i /S t a r t ? r e v =3−2357834573
6
7 HTTP/1 .1 409 C o n f l i c t8 {” e r r o r ” : ” c o n f l i c t ” ,” r e a son ” :” Document update
c o n f l i c t . ”}9
10 kore@kore−hp2140 couchdb $ c u r l − i −X DELETE11
12 {”ok ” : t rue , ” i d ” :” S t a r t ” ,” r e v ”:”2−9423c28e3d23b fa03a99994d f f367c98 ”}
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 37: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/37.jpg)
The CAP theorem 15 / 35
I The CAP theorem, read more in “CouchDB: The DefinitiveGuide” [JCA09]
Availability Partitiontolerance
Consistency
CouchDB
RDBMSPAXON
eventualconsistency
enforcedconsistency
consensusprotocols
I CouchDB employs “Eventual Consistency”
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 38: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/38.jpg)
Eventual consistency 16 / 35
I Offline replication, like Lotus NotesI Delayed synchronization (push, pull)
I Deterministic conflict resolution on replication on all nodes
I Scales well for seldom concurrent writesI Structure your documents accordingly
I Ubuntu One uses this to synchronize files, contact data, etc.
I Mozilla develops a JavaScript implementation of theCouchDB API [Moz09]
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 39: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/39.jpg)
Eventual consistency 16 / 35
I Offline replication, like Lotus NotesI Delayed synchronization (push, pull)
I Deterministic conflict resolution on replication on all nodes
I Scales well for seldom concurrent writesI Structure your documents accordingly
I Ubuntu One uses this to synchronize files, contact data, etc.
I Mozilla develops a JavaScript implementation of theCouchDB API [Moz09]
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 40: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/40.jpg)
Eventual consistency 16 / 35
I Offline replication, like Lotus NotesI Delayed synchronization (push, pull)
I Deterministic conflict resolution on replication on all nodes
I Scales well for seldom concurrent writesI Structure your documents accordingly
I Ubuntu One uses this to synchronize files, contact data, etc.
I Mozilla develops a JavaScript implementation of theCouchDB API [Moz09]
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 41: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/41.jpg)
Eventual consistency 16 / 35
I Offline replication, like Lotus NotesI Delayed synchronization (push, pull)
I Deterministic conflict resolution on replication on all nodes
I Scales well for seldom concurrent writesI Structure your documents accordingly
I Ubuntu One uses this to synchronize files, contact data, etc.
I Mozilla develops a JavaScript implementation of theCouchDB API [Moz09]
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 42: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/42.jpg)
Eventual consistency 16 / 35
I Offline replication, like Lotus NotesI Delayed synchronization (push, pull)
I Deterministic conflict resolution on replication on all nodes
I Scales well for seldom concurrent writesI Structure your documents accordingly
I Ubuntu One uses this to synchronize files, contact data, etc.
I Mozilla develops a JavaScript implementation of theCouchDB API [Moz09]
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 43: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/43.jpg)
Attachments 17 / 35
I CouchDB allows you to attach files to documents
I Files are replicated, even incrementally since the next version
I You can server full Web-Applications from a CouchDB
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 44: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/44.jpg)
Attachments 17 / 35
I CouchDB allows you to attach files to documents
I Files are replicated, even incrementally since the next version
I You can server full Web-Applications from a CouchDB
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 45: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/45.jpg)
Attachments 17 / 35
I CouchDB allows you to attach files to documents
I Files are replicated, even incrementally since the next version
I You can server full Web-Applications from a CouchDB
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 46: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/46.jpg)
Security 18 / 35
I Simple database based access restrictions
I Using HTTP plain auth
I More fine grained access control is under discussion
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 47: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/47.jpg)
Security 18 / 35
I Simple database based access restrictions
I Using HTTP plain auth
I More fine grained access control is under discussion
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 48: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/48.jpg)
Security 18 / 35
I Simple database based access restrictions
I Using HTTP plain auth
I More fine grained access control is under discussion
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 49: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/49.jpg)
Outline 19 / 35
Introduction
CouchDB
PHPillow
Views
QA
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 50: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/50.jpg)
PHPillow 20 / 35
I Object-oriented client for CouchDB
I PHP >= 5.2 since last release (5.3 only before)
I >96% test coverageI Still in alpha state
I Since CouchDB was still “alpha” up to last month
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 51: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/51.jpg)
PHPillow 20 / 35
I Object-oriented client for CouchDB
I PHP >= 5.2 since last release (5.3 only before)
I >96% test coverageI Still in alpha state
I Since CouchDB was still “alpha” up to last month
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 52: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/52.jpg)
PHPillow 20 / 35
I Object-oriented client for CouchDB
I PHP >= 5.2 since last release (5.3 only before)
I >96% test coverageI Still in alpha state
I Since CouchDB was still “alpha” up to last month
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 53: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/53.jpg)
Document examples 21 / 35
I Document creation example
1 // Crea te a document2 $doc = new phpi l lowUserDocument ( ) ;3 $doc−> l o g i n = ’ ko re ’ ;4 $doc−>name = ’ Kore Nordmann ’ ;5 $doc−>data = ar ray (6 ’ ma i l ’ => ”kore@php . net ” ,7 // . . .8 ) ;9 $ i d = $doc−>save ( ) ;
10
11 // Fetch a document by ID12 $doc = new phpi l lowUserDocument ( $ i d ) ;
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 54: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/54.jpg)
Outline 22 / 35
Introduction
CouchDB
PHPillow
Views
QA
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 55: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/55.jpg)
Map-reduce-views 23 / 35
I “MapReduce is a software framework introduced by Google tosupport distributed computing on large data sets on clustersof computers.” [Wik09]
I Used by CouchDB to implement views
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 57: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/57.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 58: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/58.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 59: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/59.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 60: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/60.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 61: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/61.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 62: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/62.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 63: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/63.jpg)
Map-Reduce 25 / 35
I Map and reduce functions are customI Defined in any language
I ECMAScript (Spidermonkey), PHP, Ruby, Python, Erlang, . . .
I Multiple map-reduce-functions (per document)
I Keys and values may be any JSON data structure
I Reduce is optional, mapping serves as a document index
I Reduce may be applied to subsets of the documents
I Reduce may be grouped
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 64: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/64.jpg)
Wiki 26 / 35
I Index all documents by their title
1 f u n c t i o n ( doc )2 {3 i f ( doc . type == ” w i k i p a g e ” )4 {5 emit ( [ doc . namespace , doc . t i t l e ] , doc . i d ) ;6 }7 }
I No reduce function
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 65: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/65.jpg)
Wiki 27 / 35
I Index all documents by their title
1 [ ” d e v e l opmen t w i k i ” , ” Bu i ldModu leDes ign ” ] => ”w ik i page−d e v e l o pmen t w i k i b u i l dmodu l e d e s i g n ”
2 [ ” d e v e l opmen t w i k i ” , ” Cod i n gGu i d e l i n e s ” ] => ”w ik i page−d e v e l o pme n t w i k i c o d i n g g u i d e l i n e s ”
3 [ ” d e v e l opmen t w i k i ” , ” D i s c u s s i o nP r o t o c o l s ” ] => ”w ik i page−d e v e l o pm e n t w i k i d i s c u s s i o n p r o t o c o l s ”
4 [ ” d e v e l opmen t w i k i ” , ”ModuleDesign ” ] => ”w ik i page−dev e l opmen t w i k i modu l e d e s i gn ”
5 [ ” d e v e l opmen t w i k i ” , ” P r o t o c o l 0 8 02 07 ” ] => ”w ik i page−d e v e l o pmen t w i k i p r o t o c o l 0 8 0 2 0 7 ”
6 [ ” d e v e l opmen t w i k i ” , ”VCSModuleDesign” ] => ”w ik i page−de v e l o pmen t w i k i v c smodu l e d e s i g n ”
7 . . .
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 66: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/66.jpg)
Outline 28 / 35
Introduction
CouchDB
PHPillow
Views
QA
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 67: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/67.jpg)
URLs 29 / 35
I Apache CouchDB: http://couchdb.org/
I Free CouchDB book: http://books.couchdb.org/relax/
I PHPillow: http://arbitracker.org/phpillow.html
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 68: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/68.jpg)
The end 30 / 35
I Open questions?
I Further remarks?I Contact
I Mail: <[email protected]>I Web: http://kore-nordmann.de/ (Slides will be available
here soonish)I Twitter: http://twitter.com/koredn
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 69: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/69.jpg)
Bibliography I 31 / 35
[JCA09] Noah Slater J. Chris Anderson, Jan Lehnardt, Couchdb: Thedefinitive guide, O’Reilly Media, Inc., 2009.
[Moz09] Mozilla, Browsercouch documentation, November 2009.
[Wik09] Wikipedia, Mapreduce — wikipedia, the free encyclopedia, 2009,[Online; accessed 27-August-2009].
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 70: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/70.jpg)
Full-Text-Search 32 / 35
I Index all documents by all their words
1 f u n c t i o n ( doc ) {2 i f ( doc . type == ” t r a c k e r i s s u e ” ) {3 // S imple word i ndex i ng , does not r e s p e c t o v e r a l l
o c cu r en c e s o f words ,4 // stopwords , d i f f e r e n t word s e p e r a t i o n c h a r a c t e r s ,
o r word v a r i a t i o n s .5 va r t e x t = doc . t i t l e . r e p l a c e ( / [\ s : . , ! ? − ]+/ g , ” ”
) +6 doc . t e x t . r e p l a c e ( / [\ s : . , ! ? − ]+/ g , ” ” ) ;7 va r words = t e x t . s p l i t ( ” ” ) ;8 f o r ( va r i = 0 ; i < words . l e n g t h ; ++i ) {9 v a l u e = {} ;
10 v a l u e [ doc . i d ] = 1 ;11 emit ( words [ i ] . toLowerCase ( ) , v a l u e ) ;12 }13 }14 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 71: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/71.jpg)
Wiki 33 / 35
I Index all documents by all their words
1 . . .2 ”a” => { t r a c k e r i s s u e −8: 1}3 ”a” => { t r a c k e r i s s u e −8: 1}4 ”a” => { t r a c k e r i s s u e −8: 1}5 ”a” => { t r a c k e r i s s u e −8: 1}6 ”a” => { t r a c k e r i s s u e −81: 1}7 ”a” => { t r a c k e r i s s u e −83: 1}8 ”a” => { t r a c k e r i s s u e −83: 1}9 ” ab l e ” => { t r a c k e r i s s u e −39: 1}
10 ” ab l e ” => { t r a c k e r i s s u e −56: 1}11 ” ab l e ” => { t r a c k e r i s s u e −73: 1}12 ” ab l e ” => { t r a c k e r i s s u e −80: 1}13 ” about ” => { t r a c k e r i s s u e −24: 1}14 ” about ” => { t r a c k e r i s s u e −43: 1}15 ” about ” => { t r a c k e r i s s u e −85: 1}16 . . .
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 72: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/72.jpg)
Full-Text-Search 34 / 35
I Reduce by word count
1 f u n c t i o n ( keys , v a l u e s ) {2 va r count = {} ;3 f o r ( va r i i n v a l u e s ) {4 f o r ( va r i d i n v a l u e s [ i ] ) {5 i f ( count [ i d ] ) {6 count [ i d ] = v a l u e s [ i ] [ i d ] + count [ i d ] ;7 } e l s e {8 count [ i d ] = v a l u e s [ i ] [ i d ] ;9 }
10 }11 }12 re tu rn count ;13 }
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>
![Page 73: CouchDB, PHPillow & PHP](https://reader036.fdocuments.in/reader036/viewer/2022071601/613d34d8736caf36b75a94a1/html5/thumbnails/73.jpg)
Wiki 35 / 35
I Index all documents by all their words
1 . . .2 ”a” => {3 t r a c k e r i s s u e −68: 6 ,4 t r a c k e r i s s u e −66: 6 ,5 t r a c k e r i s s u e −22: 4 ,6 t r a c k e r i s s u e −63: 3 ,7 t r a c k e r i s s u e −60: 2 ,8 t r a c k e r i s s u e −35: 2 ,9 t r a c k e r i s s u e −34: 1 ,
10 t r a c k e r i s s u e −31: 1 ,11 . . .12 }13 ” ab l e ” => { t r a c k e r i s s u e −86: 1 , t r a c k e r i s s u e −80:
1 , t r a c k e r i s s u e −73: 1 , t r a c k e r i s s u e −56: 1 ,t r a c k e r i s s u e −39: 1}
14 ” about ” => { t r a c k e r i s s u e −85: 1 , t r a c k e r i s s u e −43:1 , t r a c k e r i s s u e −24: 1}
15 . . .
http://kore-nordmann.de/portfolio.html
Kore Nordmann <[email protected]>