Question

If I have a script which inserts data then exits, the script will be opened by 100 users at the same time or within 2 mins.

(Actually I'm doing email tracking.)

So pconnect is better, or connect is better to reduce the resource?

I have close when after insert.

Was it helpful?

Solution

mysql_pconnect() drops the open connection into a pool that can be used by any other request to the same process. As such, each worker keeps the connection open until it dies. This can be acceptable if you keep the number of workers low, but as soon as you raise the number of workers then you're better off switching to mysql_connect(). It will take slightly longer per request since the connection has to be made each time, but you will only create as many connections as there are requests, not workers.

OTHER TIPS

connect uses fewer resources (idle instances of the web server don't need to keep a database connection open), but pconnect is slightly faster (don't have to open a new connection, it's already there).

You can also check this page for more info

http://php.net/manual/en/function.mysql-pconnect.php

Napoleon

If you use pconnect , you will have a lot of connections on SLEEP mode with this kind of script that runs 100 times in 2 minutes and your mysql will die.

You can use mysql_connect() , mysql_close()

mysql_pconnect() : is permanent connection with database. you cant lose your connection while such kind of operation.

mysql_connect() : is for connect database with normal way using some time due to large number of operation you might lose your connection.

I suggest mysql_pconnect() for database connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top