Long MySQL query, browser timeouts

I have one query that takes a very long time to process (very complicated select statement going thorugh lots of data) and my browser timeouts before it's finished. I can't do anything with the query so I need to keep the browser busy so it doesn't timeout. How do I do that?

I'm thinking I'll just let the query run in a separate thread and when it's done dump the result into a file. In the meantime, my browser will be repeatedly checking this file using ajax.

Is there a better solution? Can I just send back data to a browser so it doesn't timeout when it hangs on one query for a long time?

Thanks!
CarboneczAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
It depends on the use-case. Have you considered using AJAX?
0
Kim WalkerWeb Programmer/TechnicianCommented:
You may need to increase the mysql connect timeout in your php configuration. The default timeout is 60 seconds. You may also need to optimize your query. I ran into a similar situation recently that not only caused the connection to timeout, but also maxed out the server's RAM. I was able to improve mysql performance by creating several temporary tables.
0
CarboneczAuthor Commented:
The mysql connect timeout is not the issue (browser timeouts) and I can't optimize the query.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kim WalkerWeb Programmer/TechnicianCommented:
Have you tried entering a timeout override in your code?
0
CarboneczAuthor Commented:
Yes, the issue is browser timing out, not the script.
0
Kim WalkerWeb Programmer/TechnicianCommented:
How long are we talking about? And which browser? The browser should stay open as long as it has a connection.
0
Ray PaseurCommented:
I can't optimize the query.
Why in the world not?  Is it running on your server?

Even if you can't optimize the query, you may be able to optimize the tables with indexes.  Have you used EXPLAIN SELECT to find out what the query is doing?
0
CarboneczAuthor Commented:
It's not mine, my job is just to solve this without touching the query.
0
Kim WalkerWeb Programmer/TechnicianCommented:
You still didn't say how long. This sounds like server abuse.

And Ray's suggestion to index the tables is EXCELLENT if you haven't already done so.

Any negotiating regarding the restrictions to not touch the query?
0
Ray PaseurCommented:
This sounds like someone is setting you up for a failure by imposing a restriction on the one thing that would be most likely to succeed.  When queries run slowly there are only a very few things you can do to improve the response time.

1. Optimize the queries
2. Tune the MySQL configuration
3. Buy faster hardware
0
CarboneczAuthor Commented:
Well, it's not MySQL, it's Oracle. My mistake.

It takes 20 minutes or more. Firefox can't handle it and timeouts before there is a response. The query is very complicated and there is a lot of data being handled. I'm not the right person to optimize it and it's already been done by people who know more than me.

My job is to make sure the browser doesn't timeout and there is a response when the script finishes.

I was thinking I'd just trigger the script using ajax and then wait for the results to be dumped into some intermediate file which I'd check continuosly using ajax.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
Use an AJAX call to node.js..
0
Ray PaseurCommented:
I guess you could do that with AJAX, but this doesn't sound like it's really a suitable WWW application.  The general assumption of the internet community is that requests are atomic, complete and stateless and that responses are complete and usually instantaneous.  That's the way HTTP and RESTful applications like the WWW are expected to work.

How often is this query run?
0
MurfurFull Stack DeveloperCommented:
A 20 minute query has to make you wonder what it is doing and my first thought is inefficiency - either the database structure, poorly structured queries and/or a ridiculous number of joins. How much data is a 20 minute query expected to return to the web page (potentially loads) and is it a practical amount? The crunch though is that after a user initiates the query it simply isn't realistic to expect them to wait 20 minutes for the result.

As Ray and others have already suggested, indexes and hardware are probably your primary targets.

AJAX would be a logical approach to remove the action from the browser page but I think there may be a better approach:

Have a cron job (or similar) run the lengthy query and update a "results" table every hour or so.
Then all your page has to do is query the results table - a considerably quicker response.
0
CarboneczAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for Carbonecz's comment #a40224365

for the following reason:

Well, it worked.
0
Ray PaseurCommented:
Instead of deleting the question, please post a comment showing how you solved the problem and accept your comment as the solution.  That way we have something useful for the community to learn from.  Thanks!
0
CarboneczAuthor Commented:
This was my solution:

"I was thinking I'd just trigger the script using ajax and then wait for the results to be dumped into some intermediate file which I'd check continuosly using ajax."
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.