Top Banner
Integrating Erlang with PHP Alvaro Videla June 2010 - IPC Spring Edition - Berlin Wednesday, June 2, 2010
63

Integrating Erlang with PHP

May 13, 2015

Download

Documents

Alvaro Videla

Talk for the conference at IPC Spring Edition 2010 - Berlin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Integrating Erlang with PHP

Integrating Erlang with PHP

Alvaro Videla

June 2010 - IPC Spring Edition - Berlin

Wednesday, June 2, 2010

Page 2: Integrating Erlang with PHP

About Me

• Lead Developer at TheNetCircle.com

• Twitter: @old_sound

• Blog: http://obvioushints.blogspot.com/

• PHP Erlang Bridge Core Developer

Wednesday, June 2, 2010

Page 3: Integrating Erlang with PHP

What’s Erlang?

Wednesday, June 2, 2010

Page 4: Integrating Erlang with PHP

What’s Erlang?

• General Purpose Functional Language

Wednesday, June 2, 2010

Page 5: Integrating Erlang with PHP

What’s Erlang?

• General Purpose Functional Language

• Multi Platform

Wednesday, June 2, 2010

Page 6: Integrating Erlang with PHP

What’s Erlang?

• General Purpose Functional Language

• Multi Platform

• Invented in 1986 at Ericsson

Wednesday, June 2, 2010

Page 7: Integrating Erlang with PHP

What’s Erlang?

• General Purpose Functional Language

• Multi Platform

• Invented in 1986 at Ericsson

• Open Sourced in 1998

Wednesday, June 2, 2010

Page 8: Integrating Erlang with PHP

Products written in Erlang

Wednesday, June 2, 2010

Page 9: Integrating Erlang with PHP

Products written in Erlang

• Amazon SimpleDB

Wednesday, June 2, 2010

Page 10: Integrating Erlang with PHP

Products written in Erlang

• Amazon SimpleDB

• Ejabberd - XMPP server

Wednesday, June 2, 2010

Page 11: Integrating Erlang with PHP

Products written in Erlang

• Amazon SimpleDB

• Ejabberd - XMPP server

• RabbitMQ - AMQP Messaging Server

Wednesday, June 2, 2010

Page 12: Integrating Erlang with PHP

Products written in Erlang

• Amazon SimpleDB

• Ejabberd - XMPP server

• RabbitMQ - AMQP Messaging Server

• Riak - Decentralized Key/Value Store

Wednesday, June 2, 2010

Page 13: Integrating Erlang with PHP

Products written in Erlang

• Amazon SimpleDB

• Ejabberd - XMPP server

• RabbitMQ - AMQP Messaging Server

• Riak - Decentralized Key/Value Store

• CouchDB - Document Oriented Database

Wednesday, June 2, 2010

Page 14: Integrating Erlang with PHP

Products written in Erlang

• Amazon SimpleDB

• Ejabberd - XMPP server

• RabbitMQ - AMQP Messaging Server

• Riak - Decentralized Key/Value Store

• CouchDB - Document Oriented Database

• Mochiweb - Lightweight HTTP Servers

Wednesday, June 2, 2010

Page 15: Integrating Erlang with PHP

What’s in the package?

Wednesday, June 2, 2010

Page 16: Integrating Erlang with PHP

What’s in the package?

• Fault Tolerance

Wednesday, June 2, 2010

Page 17: Integrating Erlang with PHP

What’s in the package?

• Fault Tolerance

• Distribution

Wednesday, June 2, 2010

Page 18: Integrating Erlang with PHP

What’s in the package?

• Fault Tolerance

• Distribution

• Concurrency

Wednesday, June 2, 2010

Page 19: Integrating Erlang with PHP

What’s in the package?

• Fault Tolerance

• Distribution

• Concurrency

• Code Hot Swap

Wednesday, June 2, 2010

Page 20: Integrating Erlang with PHP

What’s in the package?

• Fault Tolerance

• Distribution

• Concurrency

• Code Hot Swap

• Mnesia a DDBMS

Wednesday, June 2, 2010

Page 21: Integrating Erlang with PHP

What’s in the package?

• Fault Tolerance

• Distribution

• Concurrency

• Code Hot Swap

• Mnesia a DDBMS

• OTP Framework

Wednesday, June 2, 2010

Page 22: Integrating Erlang with PHP

The Language

• Single Assignment

Wednesday, June 2, 2010

Page 23: Integrating Erlang with PHP

The Language

• Single Assignment

• Controlled Side Effects

Wednesday, June 2, 2010

Page 24: Integrating Erlang with PHP

The Language

• Single Assignment

• Controlled Side Effects

• Pattern Matching

Wednesday, June 2, 2010

Page 25: Integrating Erlang with PHP

The Language

• Single Assignment

• Controlled Side Effects

• Pattern Matching

• Closures

Wednesday, June 2, 2010

Page 26: Integrating Erlang with PHP

PHP Integration

• PHP Erlang Bridge

• C Extension

• Converts PHP into a “cnode”

Wednesday, June 2, 2010

Page 27: Integrating Erlang with PHP

What can I build?

Wednesday, June 2, 2010

Page 28: Integrating Erlang with PHP

What can I build?

• Web Admins for Erlang Systems

Wednesday, June 2, 2010

Page 29: Integrating Erlang with PHP

What can I build?

• Web Admins for Erlang Systems

• PHP Session Storage Systems

Wednesday, June 2, 2010

Page 30: Integrating Erlang with PHP

What can I build?

• Web Admins for Erlang Systems

• PHP Session Storage Systems

• Ad hoc K/V stores

Wednesday, June 2, 2010

Page 31: Integrating Erlang with PHP

What can I build?

• Web Admins for Erlang Systems

• PHP Session Storage Systems

• Ad hoc K/V stores

• Run Map/Reduce Jobs in Erlang

Wednesday, June 2, 2010

Page 32: Integrating Erlang with PHP

What can I build?

• Web Admins for Erlang Systems

• PHP Session Storage Systems

• Ad hoc K/V stores

• Run Map/Reduce Jobs in Erlang

• Much more…

Wednesday, June 2, 2010

Page 33: Integrating Erlang with PHP

RabbitMQ Admin Console

Wednesday, June 2, 2010

Page 34: Integrating Erlang with PHP

RabbitMQ Admin Console

Wednesday, June 2, 2010

Page 35: Integrating Erlang with PHP

RabbitMQ Admin Console

Wednesday, June 2, 2010

Page 36: Integrating Erlang with PHP

RabbitMQ Admin Console

Wednesday, June 2, 2010

Page 37: Integrating Erlang with PHP

Session Storage

• Why?

• To ease session data distribution

• Be able to add logic to sessions

• Several storage backends to choose from

Wednesday, June 2, 2010

Page 38: Integrating Erlang with PHP

Session Storage: Bitcask

• Developed by Basho as a Riak backend

• Minimalistic API

• Stores data on disk

• Easy to Backup and Restore

* http://blog.basho.com/2010/04/27/hello,-bitcask/

Wednesday, June 2, 2010

Page 39: Integrating Erlang with PHP

Session Storage: Bitcask

http://github.com/videlalvaro/phpcask

Wednesday, June 2, 2010

Page 40: Integrating Erlang with PHP

Session Storage: Bitcask

Wednesday, June 2, 2010

Page 41: Integrating Erlang with PHP

Session Storage: Bitcask

Wednesday, June 2, 2010

Page 42: Integrating Erlang with PHP

Session Storage: Bitcask

Wednesday, June 2, 2010

Page 43: Integrating Erlang with PHP

Session Storage: Bitcask

Wednesday, June 2, 2010

Page 44: Integrating Erlang with PHP

Ad Hoc K/V Store

• Using Erlang Term Storage (ETS)

• In memory tables

• Adapt the API to suit your needs

Wednesday, June 2, 2010

Page 45: Integrating Erlang with PHP

Do I have to learn Erlang?

Wednesday, June 2, 2010

Page 46: Integrating Erlang with PHP

Do I have to learn Erlang?

• NO

Wednesday, June 2, 2010

Page 47: Integrating Erlang with PHP

Do I have to learn Erlang?

• NO

• Well, Yes, a little will help.

Wednesday, June 2, 2010

Page 48: Integrating Erlang with PHP

Do I have to learn Erlang?

http://learnyousomeerlang.com/Wednesday, June 2, 2010

Page 49: Integrating Erlang with PHP

Installing the extension

• grab the code*

• phpize

• ./configure

• make

• make install

* http://code.google.com/p/mypeb/

Wednesday, June 2, 2010

Page 50: Integrating Erlang with PHP

Hello Erlang

Wednesday, June 2, 2010

Page 51: Integrating Erlang with PHP

Hello Erlang

Wednesday, June 2, 2010

Page 52: Integrating Erlang with PHP

Connecting to erlang

• peb_connect($host, $cookie);

Wednesday, June 2, 2010

Page 53: Integrating Erlang with PHP

Sending messages

• peb_send_by_name($node, $msg, $link);

• peb_send_by_pid($node, $msg, $link);

Wednesday, June 2, 2010

Page 54: Integrating Erlang with PHP

Encoding messages

• peb_vencode($format, $data);

• peb_encode($format, $data);

Wednesday, June 2, 2010

Page 55: Integrating Erlang with PHP

Encoding Examples

Wednesday, June 2, 2010

Page 56: Integrating Erlang with PHP

Formatting Characters• [] List

• {} Tuple

• ~a Atom

• ~s String

• ~b Binary

• ~i Integer

• ~d Double

• ~p Pid

Wednesday, June 2, 2010

Page 57: Integrating Erlang with PHP

Receiving Messages

• peb_receive($link);

Wednesday, June 2, 2010

Page 58: Integrating Erlang with PHP

Decoding Messages

• peb_vdecode($msg);

• peb_decode($msg);

Wednesday, June 2, 2010

Page 59: Integrating Erlang with PHP

Decoding Messages

• String, Atom, Binary -> String

• Tuple, List -> Array

• Pid -> Resource

• Integer -> Integer

• Float -> Double

Wednesday, June 2, 2010

Page 60: Integrating Erlang with PHP

RPC Calls

• peb_rpc($node, $module, $function, $msg);

• peb_rpc_to($node, $module, $function, $msg);

Wednesday, June 2, 2010

Page 61: Integrating Erlang with PHP

Resources

• PHP Erlang Bridge: http://code.google.com/p/mypeb/

• Erlang Website: http://www.erlang.org/

• Online Book: http://learnyousomeerlang.com/

• Community Site http://trapexit.org/

• Conferences: http://www.erlang-factory.com/

Wednesday, June 2, 2010

Page 62: Integrating Erlang with PHP

Questions?

Wednesday, June 2, 2010

Page 63: Integrating Erlang with PHP

Thanks!Alvaro Videla

http://twitter.com/old_sound

TheNetCircle.com

Wednesday, June 2, 2010