Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we run sql query in background

Tags:

sql

php

mysql

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..

like image 237
Nand Kishore Avatar asked Jul 11 '12 12:07

Nand Kishore


2 Answers

Run the query in a PHP script using cron and cache the result.

like image 107
472084 Avatar answered Sep 19 '22 18:09

472084


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.

like image 37
Surreal Dreams Avatar answered Sep 18 '22 18:09

Surreal Dreams