Connections to my script not closed, DB runs out of connections (wget problem?)

Discussion in 'PHP' started by alex_c, Nov 22, 2007.

  1. #1
    Hi all, my first post on these forums, please be gentle.

    I've set up a few simple php scripts to update some server statistics. I call them regularly using cron and wget.

    I've noticed that SOMETIMES, the connections to these scripts don't get closed. In WebHost Manager, I see the MySQL processes remain as "Sleep", and the Apache connections are left as "Sending Reply". The connections stay like this until the MySQL connection expires (after 24 hours, I believe).

    This doesn't seem to happen with any of the php scripts of the site itself (about 80,000 page views per day), even though there's no difference in how I set up the database connection, etc. The statistics scripts that are giving me problems simply call one or two queries, which take at most a couple of seconds to complete (worst case 5-6 seconds). The only difference that I can think of is they're called using wget.

    Annoyingly, a connection doesn't get left open EVERY time the cron job runs, which makes it harder to troubleshoot.

    I close the database connection at the end of every script. I've also added the no-http-keep-alive flag to wget. Doesn't seem to help.

    Does anyone have any hints how I could find more information about what's causing the problem? This kind of thing is never easy to isolate :(

    Since there are at least 4 systems involved - Apache, PHP, MySQL, and wget, I had to take my best guess and posted in the PHP forum. If you can think of a more appropriate place to look for help, please let me know!

    Thanks for any help,

    Alex
     
    alex_c, Nov 22, 2007 IP
  2. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This might not really help but have you considered using CURL for this process? Its very easy to implement in PHP.

    I dont know wgets too well but off the top of my head you could try.

    - Make sure you arent using persistent connections to your mysql
    - Turn keep-alives off and see if that helps.

    From your post i understand this is only happening when running scripts from the CLI and not through the browser, is that right?

    Sorry I couldnt be more help but thought any feedback is better than none :)

    Good Luck
     
    tonybogs, Nov 23, 2007 IP