14
http://adammalone.net | http://drupal.org/user/1295980 http://adammalone.net | http://drupal.org/user/1295980 Drupal and Node.js Push your site

Drupal and Nodejs - About Adam Malone... | Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980 http://adammalone.net | http://drupal.org/user/1295980

Drupal and Node.js

Push your site

Page 2: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Node.js • Server based JavaScript

• Event driven

• Asynchronous

• Non-blocking

Page 3: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Page 4: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Page 5: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Node.js – more detail • Single Process

o Great for simplicity

o Must be careful not to block the main event loop

• Multiple threads generated

• Event Loop

Page 6: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Event Loop

Page 7: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

node.js Webserver http://nodejs.adammalone.net:13337/ var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Nice and Simple node.js webserver!\n'); }) .listen(13337); console.log('Server running at http://127.0.0.1:1337/');

Page 8: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

PHP vs Node.js

• Assume I run Reuters/AP

• Necessity for speed in breaking news

• Examples are useful!

Page 9: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Drupal Integration • ‘Plumbing’ Module: Nodejs Integration http://drupal.org/project/nodejs

Page 10: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

project/nodejs • 5 Main hooks/functions

o hook_nodejs_handlers_info o hook_nodejs_user_channels

o nodejs_send_content_channel_token &

nodejs_send_content_channel_message

o nodejs_enqueue_message

Page 11: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Simplicity $commands[] = ajax_command_before('#main-wrapper', $output); $message = (object) array( 'channel' => 'chat_nodejs_auth', 'commands' => $commands, 'callback' => 'nodejsExtras', ); nodejs_enqueue_message($message);

(function ($) { Drupal.Nodejs.callbacks.nodejsExtras = { callback: function (message) { Drupal.nodejs_ajax.runCommands(message); } }; }(jQuery));

Page 12: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Extending • Drupal

o Nodejs chat module o Nodejs comments o Users online block o Breaking News o Heartbeat o File Downloads o Your module here

• Node o mymodule.server.js o Forever o Many others to hook into

Page 13: Drupal and Nodejs - About Adam Malone... |  Node.js – more detail • Single Process o Great for simplicity o Must be careful not to block the main event

http://adammalone.net | http://drupal.org/user/1295980

Why Not?

• Node.js isn’t for everything

• Do not use for CPU bound operations

• Callback spaghetti

• Lots of rage online