Php pconnect vs connect

If I have a script that inserts data, then it leaves, the script will be opened by 100 users at the same time or within 2 minutes.

(I'm actually tracking email.)

So is pconnect better or better to connect to a resource?

I have a close after insertion.

+6
php mysql-connect mysql-pconnect
source share
5 answers

mysql_pconnect() drops an open connection to a pool that can be used by any other request to the same process. Thus, each worker keeps the connection open until it dies. This may be acceptable if you keep the number of employees low, but as soon as you increase the number of employees, you better go to mysql_connect() . This will take a little longer for the request, since the connection must be done every time, but you will create as many connections as there are requests, not workers.

+4
source share

connect uses fewer resources (unused web server instances should not keep the database connection open), but pconnect is slightly faster (no new connection needs to be opened, it already exists).

+2
source share

You can also check this page for more information.

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

Napoleon

+2
source share

If you use pconnect, you will have many connections in SLEEP mode with this type of script that will execute 100 times in 2 minutes and your mysql will die.

You can use mysql_connect() , mysql_close()

0
source share

mysql_pconnect (): persistent database connection. you cannot lose the connection in such an operation.

mysql_connect (): to connect the database in the usual way, using some time due to the large number of operations, you may lose the connection.

I suggest mysql_pconnect () to connect to the database.

-one
source share

All Articles