0

I have searched for an answer, but cannot find one for this particular situation.

I am running a PHP script that runs a single MySQL query via a user search box.

Question:

If the search query takes too long, for example, more than 15 seconds, is there a way to terminate the query and present a message to the user to refine their search or to use different keywords?

I do not want the script to time out with a query and present an error due to maximum time allowed or due to the tmp file running out of space.

What would be the code to insert into the PHP script to terminate the current query process after 15 seconds and display a message?

Thanks in advance.

Prix
  • 19,417
  • 15
  • 73
  • 132
Sammy
  • 877
  • 1
  • 10
  • 23
  • [Set connection timeout](http://stackoverflow.com/questions/9562124/php-mysql-set-connection-timeout), [PHP mysql_connect set wait_timeout](http://stackoverflow.com/questions/14381276/php-mysql-connect-set-wait-timeout), [server has gone away - in exactly 60 seconds](http://stackoverflow.com/questions/1644432/mysql-server-has-gone-away-in-exactly-60-seconds) and more, kindly use the search. – Prix Mar 02 '14 at 23:32
  • Look at http://stackoverflow.com/questions/3535621/force-timeout-on-a-mysqlquery-from-php – Pascal Le Merrer Mar 02 '14 at 23:33
  • Done a quick search and came up with this: http://www.php.net/manual/en/pdo.setattribute.php `PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all drivers support this option, and it's meaning may differ from driver to driver. For example, sqlite will wait for up to this time value before giving up on obtaining an writable lock, but other drivers may interpret this as a connect or a read timeout interval.` Sounds interesting and might work if you use the correct driver, but not sure how it works. Might be useful for you to look into. – Deep Frozen Mar 02 '14 at 23:35
  • There is far too many resource on this subject including many SO answers with example, I don't think the OP did any proper research before posting his question not tried anything either. – Prix Mar 02 '14 at 23:36
  • I did do my research, but did not find anything specific to this question. – Sammy Mar 02 '14 at 23:39
  • [I am sorry but you sure didn't, the first few results on Google are straight to the point of what you're asking being the 1st link a SO question](https://www.google.com/#q=php+mysql+timeout) and from those questions from SO there listed you can find several others related. – Prix Mar 02 '14 at 23:42
  • I tried multiple Google searches. Your assuming that I used "timout" in the search. I didn't know to use "timout" in the 1st place. Plus I do not know to write a condition to terminate the query process and display a message. – Sammy Mar 02 '14 at 23:45
  • [You can also find several results with the terms you have on your question title](https://www.google.com/#q=php+mysql+terminate+query) – Prix Mar 02 '14 at 23:47
  • thanks, I guess I will have to find a solution via google and not here. I just thought there was a straight forward answer that other could use the solution without trying to piece together an answer via all the forum type posts. Some people here seem to assume that everybody who post here is a professional programmer and not a newbee. If you are a newbee, then it it difficult to piece a solution together from similar posts. – Sammy Mar 02 '14 at 23:49
  • Nope, we don't assume they are pro's **we assume they can do some efforts on searching and trying** before posting a duplicate. – Prix Mar 02 '14 at 23:54
  • Well thanks for the Google links, it's much appreciated. I will have to find an answer via trial and error which will probably take many hours to find one that will work for this answer. – Sammy Mar 02 '14 at 23:58
  • You've been given 4 links that are direct answers to your question with ways to do what you asked, you have been given a direct link to the documentation of one of the libraries on how to set it, you have been given dose of other links related to your question I don't see where you need to search anything else but read the links above mentioned on the first few comments. – Prix Mar 03 '14 at 00:00
  • Newbees- Do not post questions here expecting a direct answer. Expect answers that are links to similar questions. It's up to you to find a solution. All you will get here are pointers for you to do more research. In other words, you have to help yourself. Don't expect a direct answer from here even if someone may know it and can provide it to you. They won't provide a direct answer, you must find it yourself. This a community of pros. and not really a place for newbees to learn via posting questions. – Sammy Mar 03 '14 at 00:20

0 Answers0