Run Database Queries in Parallel?

Hello,

I have a PHP script that connects to and queries multiple remote database servers. How can I ensure these connections and queries run in parallel instead of serially so as to minimize execution time and improve end user page rendering times. And also to avoid any database connection time outs from affecting the rest of the queries.

Thank you!

What is running your PHP script? Presumably it’s either a user-induced event or a timed one.

Pageload at www.example.com/myscript.php

Thanks! :slight_smile:

Then my first suggestion is NOT to do this.

Why are you pulling from multiple databases at runtime?

Thanks for the suggestion. :slight_smile: Can you point me in the direction of an alternate recommended method?

This was the easiest way for me to accomplish pulling live data from the databases. I need to get the real time data values.

Not sure if this matters but I’m only returning a single integer value from each of the database queries and not huge datasets.

Thanks again! :slight_smile:

Ew PHP is not the way you want to do this. There are few techniques, like opening and immediately closing a web sockets that then write to a log file, and you basically have a function you call throughout the code to check this file. It’s as ugly as it sounds.

You might benefit better from using JavaScript, which can do asynchronous calls, and then update a file with an AJAX call. If the integer values you’re getting are used on the front end, you might not need PHP at all.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.