Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hello StackOverFlow community,

My Configuration :

I'm building a php app based on an MVC (C module) and I am using nginx. The session is stored in Redis (session server).

And I have node.js and socket.io runing to manage all the realTime things (Chat, presence on the page, etc...)

The node.js and php uses the same session from redis (the authentification is done only once in the PHP side) and node.js uses cookies module to use it.

The socket.io is on a port and in nginx configuration I root /socket.io/ on that port.(streaming way).

The issue or question :

The thing is that Speed is very important and I don't like php for that (the code has to compile everytime), and I need it realTime '!'. so For now I ask my socket.io to tell my visitor to do an ajax call on the php (triger the call from client side). but I don't like it not clean.

The server is 256GB RAM, 8 cores/16 threads, process 2.8-3.5GHz and the maximum visitor I'll have on each of those categories of server at the same time will not go over 1000 visitor. with different timezone so maximum 10 to 60 req/seconds.

Can I use socket.io for my data and calls ? I mean I don't have to use the event as "submit" then "on" I can do a submit() and make a callback so I don't have to send headers etc each time.

And also the alternative would be to use ReactPHP (compile once then keep runing).

Do you think it'll be stable ? (97.5%) is enough. do you have any suggestion ? Please feel free to correct me also :). If I am doing something wrong.

share|improve this question
    
Out of curiosity, what tasks are you calling the PHP backend for? –  drnugent 4 hours ago
    
Can't explain it clearly (under pattent). I just needed something stable and under 200 ms and where I now I can't do any coding mistake (php developper since php3) so I used Yaf_PHP. If I have to do it again I'll probably go for goLang or node.js so now I am mixing the php session with node.js session and migrating my code part by part to node.js . –  mbenchekroun 1 hour ago
add comment

1 Answer

It sounds like you have a good grasp on the logistics and have been able to build a solution that works but that you're a bit dissatisfied with its overall architecture.

One approach that many PHP projects use when incorporating real-time features is to use an external realtime network to pass data between clients and the server as peers. For example, PubNub provides a JavaScript SDK that allows you to publish and subscribe to chat events on different channels. On your client, you could use this code:

<script src=http://cdn.pubnub.com/pubnub.min.js ></script>
<script>(function(){

  var pubnub = PUBNUB.init({
    publish_key   : 'demo',
    subscribe_key : 'demo'
  })

  pubnub.publish({
    channel : "chat",
    message : "Hi."
  })

})();</script>

One benefit of this model in your case would be that the clients would not be forced to make server calls, or wait on the server's response, in order to proceed. Speaking of the server, here's how you would subscribe to your chat channel (assuming you are using 5.3):

$pubnub = new Pubnub(
  "demo",  ## PUBLISH_KEY
  "demo",  ## SUBSCRIBE_KEY
  "",      ## SECRET_KEY
  false    ## SSL_ON?
);

$pubnub->subscribe(array(
  'channel'  => 'chat',        ## REQUIRED Channel to Listen
  'callback' => function($message) {  ## REQUIRED Callback With Response
    var_dump($message);  ## Print Message
    return true;         ## Keep listening (return false to stop)
  }
));

PubNub also has an HTML5 chat example using Presence (non-technical overview), which allows you to determine users' connectivity status.

By moving all this activity away from your server and onto a globally-distributed realtime network, you can simplify your architecture, while maintaining your PHP server.

Good luck!

share
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.