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

Lozza's avatar
Level 4

Service for all processes

I am writing a theatre seat booking system and need to perform various functions such as generating an availability seating plan, reserving a seat during booking etc..

Whilst I've already written code to do this, I realise that it would be most efficient to control the entire functionality in a single process for all users but I know nothing about doing this!

In Laravel, is there a way for me to create a single process that runs all the time, in which I can call various functions for any user's controller?

Thank you in advance and a happy new year to you all!!

Lozza

0 likes
19 replies
martinbean's avatar

@lozza I don’t really know what you mean by a “single process” that “runs all the time”. You’ve described two separate things that should happen at two different points in time:

  1. A seating plan should be created when an event is created, based on the venue’s capacity and layout for that show (for example, arenas have different seating plans based on if the event is a musical concert versus a professional boxing event, etc).
  2. When a customer is ordering tickets, seats should be reserved from the available seats for that particular event.
Lozza's avatar
Level 4

Hi @martinbean

Basically, what I want is a single process (let's call it x) that is running all the time and occurring in memory just once on my cpanel server, even though there are 100 users. From each of these 100 user's processes, I want to send commands from each of their controllers (to be processed one at a time in a queue) to the single process x and also receive data back from x. So my questions are:

  1. Is there a facility in laravel which would allow me to do this
  2. If not, is there another way I can achieve this?

Thanks :)

martinbean's avatar

@Lozza If you’re using cPanel then that suggests you’re using a shared host, and if you’re using a shared host then they‘re not going to allow you to run continual processes. It’s not fair of you to hog resources of a server that other customers are using too.

I also don’t understand what you mean by you “want to send commands from of their controllers”. Whose controllers? The controllers are code in your application. Users don’t “have” controllers. Nonetheless, you’ve answered your own question:

to be processed one at a time in a queue

The keyword is “queue”. If you’re building a booking system, then you can use a queue to reserve a seat when a customer starts an order. But unfortunately, a queue worker requires a continually-running worker process which again, you won’t be able to run on a shared server.

Lozza's avatar
Level 4

Hi @martinbean

It isn't a shared server. Each user is running an instance of php containing an instance of my laravel application with various controllers in each. Therefore 100 users creates 100 instances of the laravel application. I want to run just 1 instance of a special controller which runs all the time and they all call it in turn. So, are you saying I am able to create a process which is known as a "queue process" which can achieve this?

martinbean's avatar

Each user is running an instance of php containing an instance of my laravel application with various controllers in each. Therefore 100 users creates 100 instances of the laravel application. I want to run just 1 instance of a special controller which runs all the time and they all call it in turn.

@lozza This makes absolute no sense.

Why would “100 users” have their own instances of Laravel applications, but then all call your controller? That makes no sense whatsoever.

I think you need to look into multi-tenancy.

Lozza's avatar
Level 4

@martinbean I am not asking you to understand the concept... only if it is possible!

martinbean's avatar

@Lozza I’ve worked on multiple event ticketing systems. I “understand the concept” quite well.

Lozza's avatar
Level 4

@martinbean Oh brillliant - please let us have a URL - it would be great to see an expert's work!

Lozza's avatar
Level 4

@snapey - I don't know everything, so I learn as I go! Perhaps you could suggest what I could learn to achieve this requirement?

Snapey's avatar

@Lozza one user sends a request. The server sends the reply, then your server has 0 users.

If your site is really busy and depending on how long your request takes, you may get one request followed quickly by another and another, now you have 3 concurrent requests so your server is only serving 3 users.

You might have 1000's of 'users' before you need to handle 100 concurrent requests.

With standard PHP installation, nothing is long running and the entire world is built and destroyed on every request.

You would retrieve the data you need to serve your users request, process the data and the user's input, update the database and return the response to the user.

You can centralise domain logic in a service provider, which your controllers can call, but this service will be started when required. The service when initiated will be handling one specific event (assuming your site does not only deal with one event)

Lozza's avatar
Level 4

@Snapey Thanks for the detailed reply!! I think I maybe should have used the word "Session" rather than "User".

It may well be that I am worrying about nothing.. but it is likely that for an initial burst, there will be over 100 customers attempting to use the booking system at the same time.

Each of these users will be presented with a 2000 seat plan (for which I need to show if each of those seats are available), on which each may click on a single seat to reserve it. Once a user has reserved this seat, the next user that is presented with a seat plan will show the reserved seat as unavailable... etc... To generate an up to date seat plan, I need to query a couple of mysql tables to see what seats have currently been sold / just clicked on and generate the available/unavailable seats accordingly.

My thoughts are, if 100 users are online at the same time, it would save processing if a service could be running which could always knows the up to date information and therefore could just send the up to date seat plan without having to perform all the mysql queries to build it.

It may be that my server could handle 100 users and it's not a problem but I've not built a system like this before.

I was just trying to ascertain if it is an option?

Snapey's avatar

@Lozza So you see its complicated. Having one process that has to handle all the different sessions is making the problem more complicated, when you have not yet proven that you have a throughput problem.

In addition, your single service will probably only handle one event on one day. What about a second event ? or a third event? or the same event on 20 days.... how many single long running processes do you expect to need?

Lozza's avatar
Level 4

@Snapey You make a good point!!

I have been programming websites for 23 years but I've never created something where I know in advance that there is going to be a huge surge on the first day, so I am just trying to make sure the server doesn't die during this time!!

For testing, I do intend writing a script to randomly select seats and to run this multiple times concurrently.

To be honest, I was really just testing the water here to see what my options are so I can make the best decisions! Maybe if I do decide to write a service such as this, it would be better in nodejs for example!

Another idea I had was to create some kind of virtual waiting room, so that only so many users can gain access to the booking system at once. Is that easily achievable in Laravel?

In response to your question, it is an annual event so there would only be a need for a single service.

martinbean's avatar

@Lozza I still don’t really understand why there are “100s” of “other Laravel applications” if you’re the one creating the seating plans and selling the tickets?

Lozza's avatar
Level 4

@martinbean - please don't worry about it but thank you for being so helpful :-)

thugic's avatar
thugic
Best Answer
Level 25

2000 seats and 100s users is something a tiny server can handle without any issues. How I would do it (oversimplified):

  • A DB table for seats with a nullable reserved_at timestamp column (null when available, filled when it's reserved), and obviously the reservation data columns (those can also be stored in a different table)
  • A view that presents users with the seat plan, marking the reserved ones as non-selectable
  • That same view, subscribes to a websocket channel, and every time there's a reservation, a websocket is sent to the view, and the view marks that seat as reserved (no need for a new DB query that way)
  • When a user starts the reservation, you take an atomic lock on that seat, and dispatch a websocket to mark the seat as "reservation in progress" or something like that
  • If two users try to reserve the same seat, you take a DB lock on the seats row, and check if the row has been marked as reserved, if it's not, go on with reservation, if it was reserved in the meantime, you show a "whoops, this seat has already been reserved" screen

There are some edge cases to consider here (I oversimplified), but I don't see a need for any long process running, other than a Laravel app on a tiny server and a websocket service/server (eg. Pusher, Ably, or Soketi).

Lozza's avatar
Level 4

Thanks @thugic for such a great answer and sorry I took so long to reply.. I have just gone on my holiday!!

I have written a process which is very similar to your suggestion, with the exception of the websocket channel, which is something I know nothing about and clearly what I need to learn about.

Currently, I have a seat allocations table which is similar to the table and holds seat allocations that have been sold.

I also have a temporary seat allocations table which is updated when a seat is clicked and this is the mysql which is inefficient and I wish to replace with the service I mentioned.

Would you have some spare time to chat about this (paid time of course)?

Thanks Laurence

Please or to participate in this conversation.