Slide 1

Slide 1 text

THE  REAL-­‐TIME  WEB   Meteor  server  and  

Slide 2

Slide 2 text

Open  source  project  developing  a   streaming  data  server  over  HTTP   UK’s  first  property  search  engine  map,  and   the  first  British  Google  Maps  mashup  (?)   Day  job.   Hats:  

Slide 3

Slide 3 text

•  Why  we  need  a  real  time  web   •  When  to  consider  integrating   real  time  data   •  Demo  of  Meteor   •  Integrating  with  PHP   •  Q&A   Agenda:   Characters reproduced (badly) from some very nifty BUPA adverts.

Slide 4

Slide 4 text

Typically  information  on   the  web  is  requested  by   the  client   Sometimes,  this  model   is  very  inefficient...  

Slide 5

Slide 5 text

Are  we  nearly   there  yet?   No.  

Slide 6

Slide 6 text

Problem:  the  client   doesn’t  know  when  to  ask   So  it  keeps  asking  again   and  again...  

Slide 7

Slide 7 text

Are  we  nearly   there  yet?   Still  no.  

Slide 8

Slide 8 text

This  kind  of  interaction  is   Short  polling  

Slide 9

Slide 9 text

Other  problems  with   short  polling   •  Repetitive  database  queries   •  Unnecessary  load   •  Bandwidth  use   •  Negative  responses   •  Cookies!   •  Delay  before  client  sees  data   •  Unpredictable  data  delivery  times   and  all  this  because…  

Slide 10

Slide 10 text

Not  everything  that  happens  on   the  web  is  driven  by  the  client  

Slide 11

Slide 11 text

So  where  does  it  come  from?   •  Other  clients/users   •  External  events   •  Status  changes   •  Progress  feedback  

Slide 12

Slide 12 text

Users  interacting  with  other  users   see  the  site  as  a  representation  of   all  those  other  people.   So,  they  need  to  know  when   their  context  changes.  

Slide 13

Slide 13 text

Meteor  keeps  each  user’s  context   fresh  with  new  information  delivered   as  it  becomes  relevant  to  that  user.  

Slide 14

Slide 14 text

Demo   Here’s  one  I  prepared  earlier*   *Apologies  for  Blue  Peter  reference  

Slide 15

Slide 15 text

It’s  the   Meteor-­‐powered  Real  Time  Teenage   Angst  Monitor     ?  

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Data  is  sent  when  it’s  ready  on  a   persistent,  preestablished     connection,  enabling:   Streaming   It’s  HTTP,  Jim,  but  not  as  we  know  it*   *Apologies  for  Star  Trek  reference  

Slide 18

Slide 18 text

Real  time  web   apps  in  PHP  

Slide 19

Slide 19 text

•  Event  controllers   •  Channels   •  Subscribers   Components  of  a  Meteor  app:  

Slide 20

Slide 20 text

•  Create  messages   •  Inject  messages  into  Meteor  on   a  channel   •  Can  read  stats  back  from   Meteor   Event  controllers  

Slide 21

Slide 21 text

Sample  event  controller  in  PHP   // Create an array of words $sayings = array("the", "quick", "brown", "fox", "jumps", "over", "lazy", "dogs"); // Open a controller channel to Meteor server $op = fsockopen("127.0.0.1", 4671, $errno, $errstr, 5); // Write a random word $out = "ADDMESSAGE demo ".$sayings[array_rand($sayings)]."\n"; fwrite($op, $out); // Read response $buf = fread($op, 4096);

Slide 22

Slide 22 text

•  Listen  on  one  or  more  channels   •  Meteor  Javascript  library   handles  comms   •  Hook  in  your  own  callback   functions   Subscriber  clients  

Slide 23

Slide 23 text

Sample  subscriber  client  JS   var mymeteor = new Meteor(); mymeteor.subdomain = “data"; mymeteor.registerEventCallback("process", newMsg); mymeteor.joinChannel("demo", 5); mymeteor.start(); function newMsg(strmsg) { alert("Meteor said " + strmsg); }

Slide 24

Slide 24 text

•  Apache:  example.com   •  Meteor:  data.example.com     •  Different  hostnames   •  Can  be  same  machine  via  port   redirection  or  IP-­‐binding   Separating  servers  

Slide 25

Slide 25 text

•  A  Publish-­‐Subscribe  system   •  A  great  way  of  broadcasting   updates  to  groups  of  subscribers   So  in  summary,  Meteor  is:   •  A  way  of  pushing  data  to   individually  addressable  clients   Meteor  is  not:  

Slide 26

Slide 26 text

Real  world  users  of  Meteor   http://ftalphaville.ft.com

Slide 27

Slide 27 text

Questions?  

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Who  is  the  user  interacting  with?   Geoff     Stockbroker,  age  49   Wants  financial  news,  and  no  mucking  about   Deirdre     Retired  teacher,  age  72   Does  her  banking  online  and  books  trips  abroad   Amy     Student,  age  23   Facebook  is  her  life   NO-­‐ONE   SITE   OTHER   USERS