FIFO shared storage for PHP and Node.js

FIFO shared storage for PHP and Node.js

Problem

I have not worked on a project of this size before, so please advise if I am taking this the wrong direction.

I need to have anywhere from 5 to 700 connections (from mobile phones), connecting on the same socket, and transmitting small packets of data to the server (CSV strings of only about 20 characters) simultaneously. No data needs to return to the phones, so just need a confirmation of arrival. The data needs to be crunched and sent to a master device, which I’m thinking will use a web-socket.

I have been an Apache/(CGI & PHP) guy for years, but I think Node.js is going to be the way to go to collect the data. Just a simple IO loop that will capture the data and send a simple acknowledgement. The heavier number crunching and serving I intend to do using C and PHP. The issue is collecting the data from the node.js server, and processing it on the Apache server.

I was thinking Redis, but I’m not very familiar with Redis specifically, so I don’t know if there is a FIFO implementation, and I don’t need the disk writting since the data will be immediately removed. I am now thinking memcached, but I still don’t know of a FIFO implementation that doesn’t rely on using timestamps (which might be what I ultimately have to use).

Any thoughts or suggestions?

Problem courtesy of: BayssMekanique

Solution

You are on the right track!

You can use redis as you wanted to implement a FIFO queue. Node.JS is a good front end for this application because it needs a minimal amount of resources and minimal crunching of data.

var redis = require("redis"),
    client = redis.createClient();

client.lpush("key","hello");
client.lpush("key","world");

Then, from the command line (or another program, such as you PHP program):

$ redis-cli
redis 127.0.0.1:6379> rpop key
hello
redis 127.0.0.1:6379> rpop key
world

It took a few hours for me to wrap my head around node and redis coming from a php/database mentality. Don’t give up, you have the right idea, you have the right software.

Solution courtesy of: jnovack

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *