Delaying execution of PHP script -


What is the best way to prevent bots, malicious users, from executing php scripts? Is it okay if I use the sleep () or SO () functions for a while "Nothing" (before executing the desired code), or it Plain stupid and better ways to do this?

Example:

  function login () {// enter entry code} function logout () {// logout enter code here}  

If I just put it, say, sleep (3000000) before login and logout code, are they okay, or better, smarter ways to get what you want?

Edit: Depending on the suggestions given below, then sleep or sleep To quit the processor, or does it cause the separation from the whole service? That means if a user + script sleep / sleeps , will all the concurrent users + scripts be delayed?

The way most web servers work (for example Apache) create a collection of thread threads have to keep. When a PHP script is executed, a thread runs PHP scripts.

When your script does sleep (100) , it takes 100 seconds to execute the script. This means that your worker thread is tied for 100 seconds.

The problem is, you have a very limited number of worker-thread - say you have 10 threads, and 10 people are logged in - your web-server can no longer serve the next Responses ..

The best way to get the maximum amount of login (or other actions) is to use any kind of fast in-memory storage thing (this is perfect for this), but for this Need to run a separate process is very complicated (If you run something like Facebook, then you can do this ..)

Simple, you may have a database table that is user_id or ip_address , first_file and failure_counter < / Code>.

Every time you get an unsuccessful login, you will (in the proxy code):

  if (last hour in the first hour) and (fail_counter & gt; ; Threshold): Return error_403 ("many authentication failures, please wait") Otherwise first_failed in the last hour: increment failure failure again: Reset first failure increased in current time_contact_content_content/ Probably not the most efficient, and the better methods, but it will prevent the animal Should - the same very well force using Memkac original, but the database has been changed from Memkac (which is faster) 


Comments