PHP request sometimes very slow
It's difficult to pinpoint the exact cause of a slow performing server from just a brief description, you're going to want to do some benchmarking to target the cause of the slow down. For example...
It could be apache's configuration (max clients could be set to a really low number - this is doubtful however). Try apache benchmark (ab)
It could be poorly constructed MySQL queries causing table locks (depending on your storage engine for each table accessed) or the MySQL connection limit being really low (check this)
It could be that your PHP scripts are really intense, and your server just doesn't have the hardware to support that level of activity.
EDIT: Take a look at munin which will give you a comprehensive overview of your server performance, then monitor it as you make the requests.
It's all very subjective. Maybe someone else could point out some other potential issues.
Related videos on Youtube
Ruu
Updated on September 18, 2022Comments
-
Ruu almost 2 years
I have a PHP/Mysql script running on a apache/php4 server (php4 is just temporary, until a new Server is ready...), and I noticed some weird be behaviour.
Requests, that use some php an a few simple mysql queries, are usually quite fast. But if I send the same request to the server 10 times (one after the other, no heavy load at all) maybe 8-9 times it will finish within 50ms. But one or two of the requests will take over 5 seconds each. Nothing in between, just ~50ms or several seconds.
It seems very random (not the first request slow, and the following fast or anything like that) and I can't find the reason.
Does anyone have an idea what might cause this problem and how to fix it?
-
zneak about 13 yearsYou may want to have PHP5 before worrying about performance.
-
Admin about 13 years50ms, you meant seconds?
-
Admin about 13 yearsno it's not what cache does, what cache does is first query slow, following fast. not same or similar queries first few fast, the one slow, again some fast etc. Maybe it's really a PHP4 thing, too bad i don't have the permission to update or move to another server on my own...
-
Admin about 13 years@BeingSimpler: i meant 0.05 seconds on normal queries vs. 5 secondson the slow ones
-
-
Luis Bosquez about 13 yearsi know the description is very vague, because i can't see any pattern/reason for this... the mysql querys are fast (not much data because just a few datasets for testing, no big joins) and the test server (2X Pentium4 2.8ghz) is pretty much idle, cpu usage maybe 1-3%. Just randomly these very slow requests
-
Luis Bosquez about 13 yearshopefully munin can help you pinpoint the problem (updated my answer with a link)