Neo
Neo

Reputation: 11557

reducing execution time of individual php files that are not mandatory to the system like Ajax JSON requests

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.

Upvotes: 0

Views: 151

Answers (2)

zod
zod

Reputation: 12417

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.

Upvotes: 0

bobdiaes
bobdiaes

Reputation: 1110

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.

Upvotes: 1

Related Questions