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 5991437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:23:10+00:00 2026-05-22T23:23:10+00:00

I am playing with phpwebsocket . Is there a way to have only one

  • 0

I am playing with phpwebsocket. Is there a way to have only one user connected at a time?

If a second user tries to connect they should be automatically disconnected and if the first user is idle for a given amount of time he should be disconnected to allow space for a new user.

Is this possible – and if so, does anyone know how?

  • 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-05-22T23:23:11+00:00Added an answer on May 22, 2026 at 11:23 pm

    It’s possible to limit usercount to one user, of course. You have to look at usercount and decide to accept or not new connections. In code it looks like this:

    if($socket==$master){
      $client=socket_accept($master);
      if($client<0){ console("socket_accept() failed"); continue; }
      else{ connect($client); }
    }
    

    You can make a further if statement to check, if usercount is 0, so you accept connection:

    if($socket==$master){
      if(count($users) == 0){
        $client=socket_accept($master);
        if($client<0){ console("socket_accept() failed"); continue; }
        else{ connect($client); }
      }
    }
    

    To disconnect a silent user, i would refresh timestamp of user evertime the user sends a message to server. Now the only thing to do is to check, if diffence between users timestamp and current time is higher then your disconnect time. If so, kick him 🙂

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

Sidebar

Related Questions

Playing around with html5 video and was wondering if there was a way to
Playing with log4net, I have seen the possibility to use a per-thread stack of
Playing with jquery for the first time, and I'm trying to get a simple
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
Im playing a little bit with heavy-client app. Imagine I have this model: class
Playing with new RTTI module, I couldn't find a way to set an event
Playing around with generating text randomly with each page refresh using php. Is there
Playing with a few tutorials on sockets but struggling to connect. My tomcat server
While playing around with one-to-one associations in castle activerecord I stumbled upon the following
Still playing with Chrome Extension and have a little problem when I want to

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.