I want to know how can we run sql query in background ... I have a big query which is taking so much time I want to run this as background so that my page loading time will be less..
Run the query in a PHP script using cron and cache the result.
You could call your queries in separate scripts with AJAX. When the page is requested, process PHP as normal, render and send the page to the visitor, and immediately kick off an AJAX script requesting another PHP script that executes the slow query. The page will be loading while the query runs, and when you get the results back from your query, use a little JavaScript to incorporate the results. The gain here is that while the page is loading the query is running, so you're doing both at once.
Also look at optimizing your query and ensure that you have set an index on your tables to speed up the query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With