Tag Archives: Inter-process communication

Diving into Node.js – Introduction & Installation

Why I Need Something Like Node.js?

First of all the use of some software is needed not because of itself, but because of the need of some specific functionality. In my case this was the need of real time news feed. Of course there is a way to make this without Node.js, as I’ll describe later in this post, but there are several disadvantages. However to begin from somewhere, let me explain what is Node.js.

Introducing Node.js

Perhaps the best way do describe what is Node.js is from its about page.

Node’s goal is to provide an easy way to build scalable network programs. In the “hello world” web server example above, many client connections can be handled concurrently. Node tells the operating system (through epoll, kqueue, /dev/poll, or select) that it should be notified when a new connection is made, and then it goes to sleep. If someone new connects, then it executes the callback. Each connection is only a small heap allocation.

In general Node is a program using the Google Chrome’s V8 JavaScript engine, which in turn is a program that can parse and execute code written in JavaScript. V8 is a very very interesting project itself. First of all from Google have developed this engine especially for one of his products – their browser Chrome. It pretends to be and by no means is one of the masterpieces of Google. It is fast and reliable engine, written in C++ and JavaScript, as Wikipedia’s page says. Actually this code is open source and can be embedded in whatever application written in C++. Thus you can have in your application a JavaScript engine. Continue reading Diving into Node.js – Introduction & Installation

PHP Functions: realpath()

Watch Out – Hard Code

Perhaps every developer knows that hard coded paths are no good! The code’s good to be flexible and extensible, but what the way to achieve that? In a typically developed application you’re completely sure the way the folders are nested will be permanent and no change will occur, and that’s maybe true, but however don’t be completely sure.

An Example

Let’s take a typical example. You’ve to access a uploaded file with PHP. By default the files are uploaded in the /tmp folder with PHP given name. That’s why immediately after the upload (the form submit) you’ve to process the _POST and the _FILES arrays and perhaps move the uploaded file somewhere else.

However you’d like to access this file wherever the application is – on the production servers or on the development server or even on the localhost!

I ran into that kind of problem/task. The thing I’d like to achieve was a bit different. I constructed the path with the dirname() function, but there were still ‘/../../’ chunks in it. So the solution is the realpath() function that removes those chunks and converts the path into one “calculated” real path to the file.

Let me show you an example:

// get the uploaded file path
$scriptPath = dirname(__FILE__);
// get the realpath to avoid the /../ part of the path
// with dirname they remain in the path
$uploadFolderPath = realpath($scriptPath . '/../../folder_name/');

If you were using dirname() you’d get something like that:


Now with realpath() the result is:


That’s more clear and even both are working correctly I’d prefer the second one!