views:

26

answers:

2

I want to make sure AJAX responses from dynamic JSON pages does not slow down the server when the SQL queries take too long. I'm using PHP, MySQL with Apache2. I had this idea to use ini_set() to recude the execution of this pages with the inline use of the mentioned method or the set_time_limit() method. Is this effective? Are their any alternatives or a mysql syntax equivalent for query time?

these are being used for example with jquery ui autosuggestions and things like that which is better to not work if they are gonna slow down the server.

A: 

If it makes sense for your application, then go ahead and set_time_limit with the desired max execution time. However, it most likely makes more sense to tweak your queries and introduce caching of query results.

bobdiaes
what do you suggest for caching query results?
Neo
A: 

memory_get_usage function can be used to find how much memory is used by your queries. as you said you can set time limit. But how this will improve your code? If your mysql query is going to take 5 mins and yu set time limit as 2 mins what will happen? Main thing is optimizing the mysql query itself. If you going to fetch huge data. try to fetch in blocks . set limit like fetch 1000 then next 1000. use indexing. make optimized joining if youare joining tables. You can use stored procedure also if it works for your application. Mysql 5 have SP.

zod
well I didn't explain well, I was gonna do this for non important stuff like ajax suggestion box. Some of my queries are dynamic and under certain circumstances can become really heavy load queries!
Neo