Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

PHP vs Node Js

PHP vs Node Js

PHP is a server side scripting language. which will compile & execute the script line by line.

Node Js is a client side scripting language, which can execute in Async & Sync mode as per the needs.

How PHP works:

  • User enters the url & click submit.
  • Will send the request to the corresponding web server to process it.
  • Web server, will validate the request type and file type.
  • If its a HTML page, its return without doing any process. else if it is a PHP page, it will redirects to PHP Interprets to compile & execute the script to return as HTML.
  • Web server returns HTML response to Browser.

How Node Js Works:

  • There is no compiler in Nodejs.
  • There is a single non blocking thread in nodejs to process all the request.
  • Memory utilization is very less compared with server side program.
  • It will process the request as much as possible, wont wait until the existing process completion.
  • Its running as though as native application.
Example:

The purpose of the program is to read text file & print as it is.

Before staring created static file named as “data.txt”.

PHP:


NodeJs:

var fs = required('fs');

	console.log("Starting...\n");
	
	fs.readFile('data.txt', function(error, data){
	
		console.log("Content of the file" + data+ "\n");
	});
	
	console.log("Ended....");

PHP Output:


Starting...
Welcome to Drtuts data file
Ended...

NodeJs Output:


Starting...
Ended...
Welcome to Drtuts data file

Conclusion:

PHP executes line by line, waits till the running process to complete and starts next line. but in NodeJs, Will initiate the request and get the response once the process has completed. until it process next line.

The post PHP vs Node Js appeared first on Drtuts.



This post first appeared on Drtuts, please read the originial post: here

Share the post

PHP vs Node Js

×

Subscribe to Drtuts

Get updates delivered right to your inbox!

Thank you for your subscription

×