PHP request sometimes very slow

6,266

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...

  1. It could be apache's configuration (max clients could be set to a really low number - this is doubtful however). Try apache benchmark (ab)

  2. 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)

  3. 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.

  4. 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.

Share:
6,266

Related videos on Youtube

Ruu
Author by

Ruu

Updated on September 18, 2022

Comments

  • Ruu
    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
      zneak about 13 years
      You may want to have PHP5 before worrying about performance.
    • Admin
      Admin about 13 years
      50ms, you meant seconds?
    • Admin
      Admin about 13 years
      no 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
      Admin about 13 years
      @BeingSimpler: i meant 0.05 seconds on normal queries vs. 5 secondson the slow ones
  • Luis Bosquez
    Luis Bosquez about 13 years
    i 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
    Luis Bosquez about 13 years
    hopefully munin can help you pinpoint the problem (updated my answer with a link)