Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

atmden's avatar

Laravel Reverb - send event and wait response

Hello! I need your help. I use Laravel Reverb as Websocket server. We are developing a mobile application. We send an event to the mobile application and we need to receive a response to this event within a certain timeout; if the response is not received, we need to send another event to another channel. Maybe there is another better solution I kindly ask you to help me solve this problem.

0 likes
7 replies
martinbean's avatar

@atmden It might be better if you explained the problem you’re trying to solve, rather than how you’re trying to solve it.

What are these “events” and why is a response within a predefined length of time needed?

atmden's avatar

@martinbean I need to send information about a new order to the mobile application. Invite the user to accept this order for execution. The offer will be valid within a few seconds. And if the user does not accept this order, I will send an offer for this order to another user.

martinbean's avatar

@atmden I don’t see why you need WebSockets are the initial “here’s an order” message?

Sounds like a food delivery app like Uber Eats. If that’s the case then sure, broadcast an event to riders when an order is placed, giving riders the opportunity to accept or reject the order. You just need to make a normal HTTP request to an endpoint to accept/reject the order. If the order is accepted, broadcast an event to other riders saying the order is no longer available. If the order is rejected, then just keep broadcasting it to other riders.

atmden's avatar

@martinbean Yes that's right. An app like food delivery. According to the rules of the application, I cannot broadcast the event to all delivery workers at once. I have to sort them into groups, such as by rating or by distance from the destination. And send messages in portions to each group of delivery workers. And if no one from the first group accepted the order, I have to send a message to the next group. And suppose that someone from the first group was unable to reject the order (the phone turned off, the Internet turned off) - I will not receive a rejection and will not understand that I need to send a message to another group. Therefore, I need some kind of timeout on the backend and not depend on the mobile application. What do you think?

1 like
martinbean's avatar

@atmden So send broadcast the order. If it’s not accepted or rejected by any one after a certain length of time, broadcast again to the next “group”.

atmden's avatar

@martinbean Heavy load on the application is expected. Can you tell me how I can check whether an order was accepted or rejected? I don't want to do this in the main application thread. There are 2 ideas to use delayed jobs, but they do not guarantee timely launch. I can use processes, but I will also have questions about them. And how would you recommend storing data for speedy delivery of orders? Redis, MongoDB?

martinbean's avatar

@atmden Stop over-complicating the problem. When a rider accepts or rejects an order, you need to actually persist that reaction somewhere, no matter how much load you’re “expecting”.

Please or to participate in this conversation.