Jump to ratings and reviews
Rate this book

Node.js for PHP Developers: Porting PHP to Node.js

Rate this book
If you’re an experienced PHP developer, you already have a head start on learning how to write Node.js code. In this book, author Daniel Howard demonstrates the remarkable similarities between the two languages, and shows you how to port your entire PHP web application to Node.js. By comparing specific PHP features with their Node counterparts, you’ll also discover how to refactor and improve existing PHP 4 or PHP 5 source code. At the end, you’ll have two fully functional codebases to provide to your users. You can update both of them simultaneously, using this book as a reference to important aspects of PHP and Node.js.

284 pages, Paperback

First published November 29, 2012

2 people are currently reading
20 people want to read

About the author

Daniel Howard

120 books

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
1 (6%)
4 stars
4 (26%)
3 stars
7 (46%)
2 stars
1 (6%)
1 star
2 (13%)
Displaying 1 - 4 of 4 reviews
Profile Image for Steve Mostafa Dafer.
16 reviews3 followers
December 18, 2016
I found it easier to learn node.js from scratch than comparing it to PHP... It's a nice book to read after you've learnt the basics of node.js, not while you're about to learn them.
Profile Image for Adi.
67 reviews
February 5, 2016
The book is not about PHP, neither is it about JS. Its focus is strictly on rewriting PHP apps in JS, possibly even maintaining both at a time by awkward refactoring and a tons of regexes. Any mentions about language "mechanics" or their inner workings are sporadic and rather shallow. It is more of a hammer-all-things approach.

It is also not clear how much "modern" (guessing +5.2 :)) PHP the author has written. To cherry pick one example, he feels comfortable stating that PHP class constructor functions mostly look like this:

class Cat {
function Cat() {
// rather than __construct
}
}

Of course, the syntax is correct at the time of the writing (PHP 7 finally deprecates it). It is also very old, even taking into account that the book itself is from 2013. On the plus side that translates neatly into JS code, which seems to be the only worry the author had written this book.

JS is also tricky as shown by one of the first examples:

var initreq = require('./initreq.njs');

exports.serve = function(req, res) {
var pre = {};
initreq.initGET(req, pre, function() {
initreq.initPOST(req, pre, function() {
initreq.initCOOKIE(req, pre, function() {
initreq.initREQUEST(req, pre, function() {
initreq.initSESSION(req, pre, function() {
page(req, res, pre, function() {
var cookies = [];
for (var c in pre._COOKIE) {
cookies.push(c + '=' + pre._COOKIE[c]);
}
res.setHeader('Set-Cookie', cookies);
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end(res.content);
});
});
});
});
});
});

Which is supposed to set stage for replicating one of the dubious features of PHP -- request super-global arrays.

Most time is a wild ride through each syntax element to another and figuring out how to find/replace them to automatically convert them into something resembling syntactically correct JS. At the end it is just a reprint of phpjs.org.

I have a lot of respect for O'Reilly Publishing and that is the only reason I persevered to the end of this book. However that sacrifice was not rewarded with any, even the smallest, pearl of knowledge. Unless you actually plan to convert PHP app into JS code with minimum design effort then you can skip this ordeal. I did it, so you do not have to.
Profile Image for Louy لؤي.
8 reviews6 followers
December 11, 2013
This book discusses many things in php to js conversion but misses one basic thing: The app structure.
The way the book presented how to convert the http engine to nodejs is very weak in my opinion.
Displaying 1 - 4 of 4 reviews

Can't find what you're looking for?

Get help and learn more about the design.