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

thindery's avatar

Real Time Data from a Database and updating a View

My company has some legacy desktop programs that run on an Oracle database. These applications do some manufacturing logic and create database records about the orders. I need to use Laravel to pull in "real time" data about orders and that is where I am not sure how to do it.

We get new orders placed every few seconds. Using the yajra/laravel-oci8 extension I can pull up our table of orders. A quick page refresh will pull in the new ones that were placed just a few seconds ago. I'm connected to the remote oracle database and pulling in the info.

But how can I have the page be "live" and continually update the top of the table view with the latest orders? I thought Ajax requests on a timer.. but that seems clunky.

I've looked into sockets and Laravel Echo.. but I don't understand how I can use that in this case. There aren't "events" or anything that get broadcasted. The Oracle database simply has new records written to it.

Any thoughts and tips on what I can look into would be greatly appreciated!

0 likes
4 replies
aardalich's avatar

You're wanting the user to be sitting on a page which shows the orders and that the orders shown keep updating without the user needing to refresh the page?

Can see 3 ways, and you've mentioned 2 of them.

Simply using a meta refresh tag to tell the browser to refresh the page every so often

Within the head tag on the page

<meta http-equiv="refresh" content="3;url=https://www.page.com/orders" />

where 3 refers to the seconds before the refresh

Ajax, writing a javascript function to grab new data to display every so often

Web sockets using something like pusher.com might be an extreme solution just to refresh a bit of data on a page. In this scenario, you'd have some code which would be checking for new orders (e.g. a console job) and if it saw a new one, broadcast the new order, or just the fact that there is a new order, which you then listen for in javascript and push in the new order onto the page, or, trigger an ajax method or a page refresh to pull the orders and show them.

To take that last option further, if there is an option in Oracle to setup a trigger, so that when a new order is created, another table is updated with the new order's id and you have a service that monitors that table instead, or a view of that table. Might be an option if monitoring the actual orders table is expensive database time wise if it is a very large table, although, setting triggers on very large tables can be expensive in their own right.

Snapey's avatar

You could trigger a push to the client with a Cron job, and the most frequent update would probably be one minute.

You could start a job with cron, that ran for e.g. one minute, pushing changes every 10 seconds for instance, and then died to be retriggered again.

Or just from the client side, use a 'long poll' technique. The client initiates a javascript request to the server, but the server does not reply right away, but waits whatever interval you need and then runs the query and replies. The client displays the updated data and immediately sends a new call.

Or just delayed at the client side, Client updates the view every x seconds.

various factors are important like how often you want it to update and how many clients there are. For instance, if this was one or two clients every minute, I would probably refresh by the client. But if there are 100 clients all asking for the same data, I would push from the server to all the listening clients (significantly cuts down on the queries on the oracle database)

thindery's avatar

Thanks for the input! These suggestions give some options to explore. I didn't consider the number of clients that can be connected. Long term it needs to be pushed from Oracle so I'll be looking to go this route.

robrogers3's avatar

FYI, we do something similar with ajax and setInterval. It's super easy to implement. And if there's new data, then it justs updates the page data. (a table too)

1 like

Please or to participate in this conversation.