Integrating Erlang with PHP Alvaro Videla June 2010 - IPC Spring Edition - Berlin Wednesday, June 2, 2010
May 13, 2015
Integrating Erlang with PHP
Alvaro Videla
June 2010 - IPC Spring Edition - Berlin
Wednesday, June 2, 2010
About Me
• Lead Developer at TheNetCircle.com
• Twitter: @old_sound
• Blog: http://obvioushints.blogspot.com/
• PHP Erlang Bridge Core Developer
Wednesday, June 2, 2010
What’s Erlang?
Wednesday, June 2, 2010
What’s Erlang?
• General Purpose Functional Language
Wednesday, June 2, 2010
What’s Erlang?
• General Purpose Functional Language
• Multi Platform
Wednesday, June 2, 2010
What’s Erlang?
• General Purpose Functional Language
• Multi Platform
• Invented in 1986 at Ericsson
Wednesday, June 2, 2010
What’s Erlang?
• General Purpose Functional Language
• Multi Platform
• Invented in 1986 at Ericsson
• Open Sourced in 1998
Wednesday, June 2, 2010
Products written in Erlang
Wednesday, June 2, 2010
Products written in Erlang
• Amazon SimpleDB
Wednesday, June 2, 2010
Products written in Erlang
• Amazon SimpleDB
• Ejabberd - XMPP server
Wednesday, June 2, 2010
Products written in Erlang
• Amazon SimpleDB
• Ejabberd - XMPP server
• RabbitMQ - AMQP Messaging Server
Wednesday, June 2, 2010
Products written in Erlang
• Amazon SimpleDB
• Ejabberd - XMPP server
• RabbitMQ - AMQP Messaging Server
• Riak - Decentralized Key/Value Store
Wednesday, June 2, 2010
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
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
What’s in the package?
Wednesday, June 2, 2010
What’s in the package?
• Fault Tolerance
Wednesday, June 2, 2010
What’s in the package?
• Fault Tolerance
• Distribution
Wednesday, June 2, 2010
What’s in the package?
• Fault Tolerance
• Distribution
• Concurrency
Wednesday, June 2, 2010
What’s in the package?
• Fault Tolerance
• Distribution
• Concurrency
• Code Hot Swap
Wednesday, June 2, 2010
What’s in the package?
• Fault Tolerance
• Distribution
• Concurrency
• Code Hot Swap
• Mnesia a DDBMS
Wednesday, June 2, 2010
What’s in the package?
• Fault Tolerance
• Distribution
• Concurrency
• Code Hot Swap
• Mnesia a DDBMS
• OTP Framework
Wednesday, June 2, 2010
The Language
• Single Assignment
Wednesday, June 2, 2010
The Language
• Single Assignment
• Controlled Side Effects
Wednesday, June 2, 2010
The Language
• Single Assignment
• Controlled Side Effects
• Pattern Matching
Wednesday, June 2, 2010
The Language
• Single Assignment
• Controlled Side Effects
• Pattern Matching
• Closures
Wednesday, June 2, 2010
PHP Integration
• PHP Erlang Bridge
• C Extension
• Converts PHP into a “cnode”
Wednesday, June 2, 2010
What can I build?
Wednesday, June 2, 2010
What can I build?
• Web Admins for Erlang Systems
Wednesday, June 2, 2010
What can I build?
• Web Admins for Erlang Systems
• PHP Session Storage Systems
Wednesday, June 2, 2010
What can I build?
• Web Admins for Erlang Systems
• PHP Session Storage Systems
• Ad hoc K/V stores
Wednesday, June 2, 2010
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
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
RabbitMQ Admin Console
Wednesday, June 2, 2010
RabbitMQ Admin Console
Wednesday, June 2, 2010
RabbitMQ Admin Console
Wednesday, June 2, 2010
RabbitMQ Admin Console
Wednesday, June 2, 2010
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
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
Session Storage: Bitcask
http://github.com/videlalvaro/phpcask
Wednesday, June 2, 2010
Session Storage: Bitcask
Wednesday, June 2, 2010
Session Storage: Bitcask
Wednesday, June 2, 2010
Session Storage: Bitcask
Wednesday, June 2, 2010
Session Storage: Bitcask
Wednesday, June 2, 2010
Ad Hoc K/V Store
• Using Erlang Term Storage (ETS)
• In memory tables
• Adapt the API to suit your needs
Wednesday, June 2, 2010
Do I have to learn Erlang?
Wednesday, June 2, 2010
Do I have to learn Erlang?
• NO
Wednesday, June 2, 2010
Do I have to learn Erlang?
• NO
• Well, Yes, a little will help.
Wednesday, June 2, 2010
Do I have to learn Erlang?
http://learnyousomeerlang.com/Wednesday, June 2, 2010
Installing the extension
• grab the code*
• phpize
• ./configure
• make
• make install
* http://code.google.com/p/mypeb/
Wednesday, June 2, 2010
Hello Erlang
Wednesday, June 2, 2010
Hello Erlang
Wednesday, June 2, 2010
Connecting to erlang
• peb_connect($host, $cookie);
Wednesday, June 2, 2010
Sending messages
• peb_send_by_name($node, $msg, $link);
• peb_send_by_pid($node, $msg, $link);
Wednesday, June 2, 2010
Encoding messages
• peb_vencode($format, $data);
• peb_encode($format, $data);
Wednesday, June 2, 2010
Encoding Examples
Wednesday, June 2, 2010
Formatting Characters• [] List
• {} Tuple
• ~a Atom
• ~s String
• ~b Binary
• ~i Integer
• ~d Double
• ~p Pid
Wednesday, June 2, 2010
Receiving Messages
• peb_receive($link);
Wednesday, June 2, 2010
Decoding Messages
• peb_vdecode($msg);
• peb_decode($msg);
Wednesday, June 2, 2010
Decoding Messages
• String, Atom, Binary -> String
• Tuple, List -> Array
• Pid -> Resource
• Integer -> Integer
• Float -> Double
Wednesday, June 2, 2010
RPC Calls
• peb_rpc($node, $module, $function, $msg);
• peb_rpc_to($node, $module, $function, $msg);
Wednesday, June 2, 2010
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
Questions?
Wednesday, June 2, 2010
Thanks!Alvaro Videla
http://twitter.com/old_sound
TheNetCircle.com
Wednesday, June 2, 2010