Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:07:24+00:00 2026-06-02T15:07:24+00:00

Im trying to build an notification system with php and socket.io. The idea is,

  • 0

Im trying to build an notification system with php and socket.io. The idea is, the clients connect to socket.io and are waiting for notification. A PHP script connects to socket.io via curl on another port and posts the update even, which gets passed to the connected clients. The clients are identified via an id they send in a message after the connection event. I Store the socket variable associated to the user_id. Everything works fine, but after some time the script stops working. It seems that after some time the socket variable which is stored in an array. However my server-code is posted below

var notification_port = 8001;
var oak_port          = 8002;

var io = require('socket.io').listen(notification_port);
var clients = new Array();

io.sockets.on("connection", function(socket){
   socket.on("__identification", function(message){
      if (message.id){
         console.log("user with session id " + message.id + " connected!");
         var sockets = clients[message.id];
         if (!sockets){
            sockets = new Array();
         }
         sockets.push(socket);
         clients[message.id] = sockets;
      }
   });
});

var url  = require('url');
var oakListener = require('http').createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});

  var url_parts = url.parse(req.url, true);
  var query = url_parts.query;

  var sockets = clients[query.id];
  if (sockets){
     for (var i = 0; i < sockets.length; i++){
        sockets[i].emit("notification", query);
      }
      res.end('ok');
  } else {
     res.end('failed');
  }
}).listen(oak_port);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:07:26+00:00Added an answer on June 2, 2026 at 3:07 pm

    The problem was, that the connection gets lost about every minute. You have to gargabe collect in the “disconnect” function and re initializing the connection in the “connection” function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to build a simple faye realtime based notification system so I can
Trying to build sslsniff on a RHEL 5.2 system here. When compiling sslsniff on
Trying to build my project with ANT in idea 10 and I get a
I am trying to build a system of monitoring site / server uptime in
I am trying to build a basic plugin system like the kind you often
I am trying to build some notification control in Silverlight. When I click the
I am trying to create a notification system very much like the SO one
I am trying build an AST for the below grammer using ANTLR condition_in :
I'm trying build a method which returns the shortest path from one node to
I'm trying build an App Engine connected Android application and am having some problems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.