0

I am building a web site and want to provide public API to everobody without registration. The api will perform search function, and as database is big it will consume a lot of resources. So I want to seriously limit memory, process time, ect. Also I will use public hosting (non personal or dedicated), so I will not have any access to process control (I suppose). What do you recommend to do?

I think of using one global variable that will store last successful script executing time and will terminate script if enquery is more than in 1 sec. I was not able to find super global (across all scripts) variables, so will use file with lock on it.

But anyway, any php script execution control???

3
  • 1
    Have you considered caching ...You should think of database indexing as well and if your api's are going to be open for the public, you should also ensure you don't get any spam or sql injection.. so either create api keys or think of some form of captcha.. Commented Dec 9, 2013 at 17:49
  • Search is by index, but it is near 20k rows. Database is fine. Sql injection will be blocked as only simple words are allowed for a search. Spam - no reason how it can be used. I do not think of API keys, but anyway I will have same problem: "How to limit" Commented Dec 9, 2013 at 17:58
  • Have you done any performance testing? How do you know that your queries will take a long time and/or consume memory? 20K rows isn't "big" for MySQL, unless you have a really bad design with hundreds of columns, no indexes, inefficient column types, etc. Commented Dec 9, 2013 at 19:11

1 Answer 1

3

I guess you can control it by php_ini in global configuration, or ini_set() inside the script, by setting memory_limit and max execution time.

Here's a link to the php configuration file manual

PHP configuration file

Sign up to request clarification or add additional context in comments.

2 Comments

Can it be set for 1 script only, or it will affect everything?
Ah, good point. It'll affect everything. Try this: hk2.php.net/ini_set The answer above mentions ini_set() .. I do advice you to look at the answers provided in detail to benefit in max without expending the helper's resources :) And you should definitely mark his answer as correct!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.