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

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.

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