Integrating Node-Js With PHP
Integrating Node-Js With PHP
js with
PHP
Lee Boynton
PHPHants March 2013 Meetup
Server-side JavaScript
Apache + mod_php
Clients
Webserver
(Example borrowed from Marc Gear's excellent server side scripting smack down)
nginx + php-fpm
Still pretty similar, there is a pool of available
PHP processes
Node.js
Clients
Webserver
#1 Reason
l33tness
Websockets!!!!
Websockets
Persistent connection to server via web
browser
Low latency
Bi-directional
Much better than XHR long polling (comet)
The possibilities...
Games
News feeds
Chat
Real-time applications
Awesome!
Let's ditch PHP!
Or use the right tool for the right job...
PHP works
Familiarity, maturity
Existing code in PHP
Node still in its infancy (created in 2009)
Not as many frameworks, libraries
May have to write more code for some basic things
APIs may change, not version 1.0 yet
Memcache/redis/
something else
Session data
PHP
Session data
Node
However...
Sessions are serialized by PHP:
not|a:2:{i:0;s:4:"easy";i:1;a:1:{s:2:"to";s:5:"parse";}}
Conclusion...
Using Node is fun...
Good way to add real-time functionality to
existing website
Can be used for much more
Links
http://nodejs.org/
https://npmjs.org/
http://socket.io/
https://packagist.
org/packages/lboynton/memcached-jsonsession-save-handler
https://github.com/msgpack/msgpack-php
https://github.com/msgpack/msgpack-node