Slow response of a Php+MySql application -


i running chatroom (phpfreechat) mysql+php. have dedicated server run script can consume lots of resources. works fine 100 concurrent users. however, user threaten kill chatroom , doing :(

there 40 users , chatroom dead. takes 10-20 seconds deliver 1 message. mysql eating 300% plus cpu. however, 100 users (when it's not under attack), chatroom uses 200-300% cpu. checked following things make sure not dosing/ddosing our server.

1 - limited 3 requests per seconds. 2 - analyzed access.log see weird activity or crlf slow attacks. there none. 3 - looked per ip connections using netstat command , none has lots of connections.  4 - disabled ping of death 

static website on server works fine under attack. assuming exploiting mysql via chatroom sending many requests. ran following query see current connections mysql:

show status `variable_name` = 'threads_connected' 

the result 7 looks pretty normal. there other step can perform block attack , protect server (chatroom)?

(from last comment) ahh, means attacker trying queries using mysql injection, first have

1) sanitize inputs

if using pdo or mysqli use bind params (prepared statements) feature filter inputs

or @ least mysqliescapestring inputs

and if php page takes value .../page.php?id=10 check value & make sure integer below

if(is_numeric($_get['id'])){ //do operations...}else { //suspicious input given exit} 

2) limit query execution time

as having long running queries (which hacker), limit query execution time , use statement timeouts, wait_timeout features query have limited execution time

and said earlier in apache access log you'll find these sleep queries parameters so, find , block ip


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -