Angel \”Java\” Lopez on Blog

October 30, 2013

PHP and Node.js

Filed under: JavaScript, NodeJs, Open Source Projects, PHP, Talks — ajlopez @ 4:37 pm

This month, I gave a talk about PHP and Node.js, at PHP Dev Conference Argentina.

http://www.phpconference.com.ar/

I should write a post about my excellent experience in that conference, full of interesting topics and people.

My talk description

http://www.phpconference.com.ar/php-node-js-y-tutti-li-fiocci-2/?lang=en

We will see what Node.js means for a PHP programmer. A programming language built on top of Google’s V8 engine. Executing loops, with asynchronous IO. Node.js as a shell server, and web server. Javascript as a very flexible language, with little of the programming bloatware that’s common on other languages. A package ecosystem, very similar to PHP’s Composer. Instead of dealing with lots of functions (as we are used to with PHP), Node has modules, that we can install and utilize at any point.

Where Node.js really shines and distinguishes itself from PHP is in realtime services. We will learn about its socket and websocket support, and how important true asynchronous IO is. We will also learn about the price we have to pay for this: callbacks.

But we don’t want to walk away from our beloved PHP, so we will integrate PHP with Node.js. First approach: PHP + browser + Node.js, with little communication between PHP and Node. Then we’ll jump right into integrating Node code from PHP. dnode modules (sync and async.) And before we end the session… surprises, and tutti li fiocci!

The slides are at:

https://github.com/ajlopez/Talks/tree/master/PhpNode

The PHP code, at:

https://github.com/ajlopez/PhpSamples/tree/master/PhpNode

to be viewed from a web server (I used xampp in my notebook).

The node code, many servers to launch, each one listening by different ports:

https://github.com/ajlopez/PhpSamples/tree/master/PhpNode/Node

You must install Node.js, and then, run “npm install” in that folder. For example, if you want to launch the distributed canvas server, execute at command line: “node canvasserver”.

There are examples where the browser connects with node.js server, without using PHP. And there are examples where the PHP code talks to Node.js. I used:

https://github.com/substack/dnode

at Node.js side. And dnode PHP clients:

https://github.com/bergie/dnode-php
http://bergie.iki.fi/blog/dnode-make_php_and_node-js_talk_to_each_other/
https://github.com/erasys/dnode-php-sync-client

At the end of the talk, I presented my PHP-to-JavaScript transpiler, written in JavaScript:

https://github.com/ajlopez/PageJs

It can run minimal PHP code in the Node.js server:

Nice!

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

2 Comments »

  1. […] Give a talk about PHP and Node.js [complete] see post and PHP/Node repo and PageJs repo at PHP Dev Argentina 2013 – Give a talk about TDD with ASP.NET […]

    Pingback by New Month’s Resolutions: November 2013 | Angel "Java" Lopez on Blog — November 2, 2013 @ 1:49 pm

  2. […] Dar una charla sobre PHP and Node.js [complete] see post and PHP/Node repo and PageJs repo at PHP Dev Argentina 2013 – Dar una charla sobre TDD con ASP.NET […]

    Pingback by Resoluciones del Nuevo Mes: Noviembre 2013 - Angel "Java" Lopez — November 5, 2013 @ 10:54 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: