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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:13:17+00:00 2026-06-14T04:13:17+00:00

I’m a beginner with PHP/MySQL and new to javascript as well, I want to

  • 0

I’m a beginner with PHP/MySQL and new to javascript as well, I want to make a page that one user could send a real-time request to another user. For example, UserA could see the list of online users, and send a request to UserB (online), UserB’s page would have a popup alert, and UserB has the option to click Yes or No. UserA would receive a popup with B’s response (or if timed out then default to No)

How is this usually done? I guess my questions has 2 parts:

  1. how to record online/offline users? (should I have a table
    recording login/logout times?)
  2. how to usually send message
    between 2 users
  • 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-14T04:13:18+00:00Added an answer on June 14, 2026 at 4:13 am

    I don’t know what you are trying to make, but I assume that a private chat is a good example? I’ll pretend that that is what you are doing.

    I’ll try to give a decent amount of information where appropriate without turning this into a complete tutorial. Expect a good spattering of links and suggestions to read things.


    The Idea

    You have one basic idea at the core of your application, User Communication. You need to somehow go from the stateless, asynchronous world of HTTP to a stateful, synchronous one. There are a few ways to do this.

    Polling

    This is using AJAX to repeatedly request information from the server. AJAX stands for Asynchronous Javascript And XML, don’t worry about the XML bit though, that’s just historical. Basically, AJAX is like making a regular request from a script in a browser, this gives you the advantage of being able to send and receive data from the server without a refresh. This is good for situations that are either user-initiated or can handle a delay. For your case, you would mark the last time somebody took an action, then specify some timeout to decide when somebody is offline. The result of the request contains any new messages that may have arrived since they checked.

    Long-Polling/Comet

    This is an extension of the polling idea before. This is almost explicitly a workaround for the client-initiated nature of basic AJAX. Comet is essentially just AJAX, but you keep the connection open for a much longer time, allowing the server to push information down. You can find information out on this technique here: Comet. However, there are a few issues with this technique:

    • Flaky experience. Different browsers will handle a long-open connection differently, making it a challenge to provide a consistent experience for all users in all browsers.
    • Disconnects. Eventually there will be a disconnect. Eventually the browser calls .abort() on the request and you have to re-open it.
    • Single-connection limitation. The HTTP/1.1 standard says that a browser can only have one simultaneous connection open at a time per server. You can work around this by using multiple (sub-)domains.

    You have to use essentially the same techniques as before, due to the fact that you still have disconnects that are part of the normal usage. The difference is that the server has to keep the connection open for as long as necessary. Depending on what technology you use in the back-end, this can be anywhere from trivial to difficult and can potentially inflict a significant performance cost if not handled carefully.

    WebSockets

    WebSockets are essentially the previous solution, but standardised and implemented properly. The essence of WebSockets are that you can make a regular request to the server, but ask that be upgraded to a TCP connection. The word upgrade here is a bit misleading, as it technically just drops the HTTP stuff from the connection and leaves you with the raw underlying connection.

    WebSockets are designed for persistent connections and are full-duplex (communication both ways).

    There are, however, two major downsides: They are new, which means that support isn’t that widespread, most modern browsers support them, but you can’t rely on everybody having an up-to-date browser. Server side support is required. This means that you have to have a system that is capable of upgrading the requests and handling them efficiently, again, because this is a new technology, support is limited, with socket.io being the major one. socket.io is a node.js module and therefore might not be suitable for you. Other languages/technologies are out there, but there is decidedly less support available.

    (EDIT: Reread your question and saw that you are using PHP, you can use this library: php-websocket for websockets. I haven tested it, so caveat emptor)

    With WebSockets, you can use the connection dropping as an offline signal and you just send the data around as you need to. However it is wise to fall back to a older, more reliable solution if WebSockets aren’t available, so try to keep that in mind.


    There a still numerous issues around all of these solutions that you will need to solve, but hopefully this should give you some idea of where and how to start. At the very least it provides a number of phrases you can google (or bing or duckduckgo or ask)!

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker

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.