#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    The best way to log websocket chats


    I'm currently working on a web app, I'm working on a chat app feature. I want to create a real-time chat feature that uses websockets, and phpwebsocket as ws server, i want the chats to be logged in a database, my question is, which one of the following will be the best practice in terms of user experience and web server performance:

    1. whenever a clients sends a message, the message is first sent to the server via ajax and a script does the necessary processing and logs it to the database, then return true, then on success it return information back to the client, then a callback function sends the message to the websocket server and the server just relays it to the recipient.
    2. whenever the client sends a message, the message is sent to the websocket server and the websocket does the processing and posting to the database then on success it relays the message to the recipient.
    My concern of the second option is putting too much load on the websocket server, since it is a single script serving different clients.....Any help will be greatly appreciated
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    What sort of processing are you doing on the message?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by E-Oreo
    What sort of processing are you doing on the message?
    Well its basically inserting messages into the database for now.
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Are your web socket server and your logging server different machines? If not, then your first method sounds like it would double the number of HTTP requests for no particular reason, which would place a much higher load on the server.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by E-Oreo
    Are your web socket server and your logging server different machines? If not, then your first method sounds like it would double the number of HTTP requests for no particular reason, which would place a much higher load on the server.
    They are in the same machine. My main concern is the websocket server response time, lets say if there are 1000 users, then they send messages simultaneously, the websocket server script will have to first insert the message to the database and then relay it to the recipient, wont the database queries and insertions affect the performance of real time chats, especially as the number of users grows. By my understanding PHP doesnt allow parallel functions so each message is queued. I have little over 5 months with PHP so i might be missing something. Your replies are greatly appreciated

IMN logo majestic logo threadwatch logo seochat tools logo