V
V
Vadim Stepanenko2018-02-27 21:55:47
PHP
Vadim Stepanenko, 2018-02-27 21:55:47

Why is websocket php taking a very long time to complete a request?

Hello! I use this socket chat on the site. There was a need to save each message in the database. As a result, in the server.php file, in the loop where it checks for new messages in the chat (line 46) on the github in server.php, I connected redbean.php via require_once, and then the usual construction for adding an entry to the database:

spoiler
$add2Db = R::dispense('chatmes');
      $add2Db->reg_data = time();
      $add2Db->username = $user_name;
      $add2Db->message = $user_message;

      R::store($add2Db);


But now, when sending a message, it takes more than 2 seconds before the message is displayed.
How do they implement this without delay? What can you advise?
Thanks to everyone who will respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2018-02-27
@VladimirAndreev

1. What prevents that library from being connected 1 time at the beginning of the script?
2. Supplement the code with the collection of timestamps - so it will immediately become clear what specifically slows down

V
Viktor, 2018-02-28
@Levhav

Here are my articles where I describe how you can make a chat without delay in the delivery of messages and so that the database is not loaded with a lot of requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question