On my server, i have all requests for a jpg or mpg file going thru a php script, which then connects to mysql.

this could lead to hundreds of connections per second

should i use mysql_connect when connecting or mysql_pconnect?

is mysql_pconnect for each user loading the script? that is.. person a loads site, a persistent connection is created with him. b loads site, persistent connectino is created with him too. Or is it that only one connection is created, and shared amonst all requests by php files?

which should i use? pconnect or connect?

    Use mysql_connect();
    Do a search you will find a number of threads on this topic explaining why.

      but why? from what i understand.. its the same thing

      mysql_connect open a connection when its requested. one request per day means its open for like 30 seconds. 20 requests a second means 20 threads are opened

      msql_pconnect keeps a connection open. one request per day means its open for the day. 20 requests per second means all 20 use that one thread..

        Nope.

        Look at the threads and read the manual. Each script that is actually running will always have it's own connection. Connections are never shared between running scripts.

        When pconnect is used, the connection is not closed when the script exits. When a new script starts, it may end up using the same connection assuming all the connection information is the same. All you really save is the slight amount of time required to actually open a connection.

        The downside is if the previous script happens to have a lock a table and did not unlock it then the table stays locked for ever more. And that is a bad thing.

          Write a Reply...