Hi folks,

I cruised this group looking for this particular problem but didn't find it. Hope it hasn't been answered ad infinitum already.

I'm running PHP 4.0.4 on an Apache 1.3 server using MySQL 3.23.33. I developed my code on a Win2K workstation box, then ported my code over to Mandrake Linux 7.1 with the same software installed. Everything worked fine, EXCEPT the pconnect I issue on a successful login no longer works. As a stop-gap measure I added connect statements to each page, but it would make my life a lot simpler if the pconnect did it's thing. Has anyone encountered this before, and if so, what's the solution?

Chris

    don't use pconnect. pconnect is evil 99% of the time. instead, use an include() for a header at the top of every page to create the db connection and a footer to close the db connection.

      Brandon is spot on here. If you're not having performance issues, pconnect is dangerous. Primarily the issue is the way PHP handles persistant connections.

      The skinny is that you have to have your database setup for more max backends than you have apache front ends, or PHP/Apache will starve for connections to the database. The reason is that each pconnect connects to the database persistantly via a single apache child process. The connection doesn't go away until the child process is killed by the master apache process.

      So, if you have apache setup for 150 max children, and postgresql set up for 75 max children, you will eventually run out of backends processes for apache to talk to.

      Increasing the max number of postgresql backends can be hazardous, as each one eats a fair bit of memory, and having hundreds of idle backends sitting around causes some performance problems itself.

      Plus, if your kernel params don't allow for enough file handles to be open, then apache/postgresql may not be able to open all the children you've set them up to open, and the users will start getting no output.

      Dropping the max number of apache children may result in denied access to users if you routing have hundreds of simo accesses with keep alive and such turned on.

      What would be nice is if PHP had a real backend pooling algorhythm that could create, say, two dozen connections, then pass them off to whichever script needed them then reuse them individually.

      If you must use pconnect, make sure you have the memory / system resources to handle it, it's a memory hog.

        Thanx to Brandon and Scott for their input. As it happens, access to all the scripts is blindingly fast, even with a connect on every page, so overhead is obviously not a problem even when there are lots of users. I think I'll just pretend that pconnect doesn't exist...

        Thanx again,
        Chris

          Write a Reply...