Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mysql_connect resource is allways the same

I'm having a problem my php script witch you can see here: http://codepad.org/F0qhElRC

Is not opening a new resource for each connection from a child. Already I tryed using 127.0.0.1 or my local network IP but nothing worked, also max_user_connections in mysql is set to 0 opening a connection from web gives me a different resource for the web. But in the command line it uses the same.

In mysql_connect I specified new_link to be true, I placed a __destruct in the bd class to close the connection if the child get's destroyed. Closing the connection does not make php open a new one even after I restart the script. The resource could be free and so I should count on that but in the childs I also have tryed placing a sleep but that doesn't make it run a new resource.

Any sugestions on how to debug this?

Basically I whant a new conn for every new script or child call.

Thanks in advance. Best regards,

like image 760
Fernando André Avatar asked Mar 23 '26 19:03

Fernando André


1 Answers

You've managed to omit all the relevant code, but many database extensions in PHP reuse currently open connections unless you specifically instruct them not to do so. If you are using mysql_connect(), have a look at the $new_link parameter:

mysql_connect — Open a connection to a MySQL Server
Report a bug
Description
resource mysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]]]] )

Opens or reuses a connection to a MySQL server.

.

new_link

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. In SQL safe mode, this parameter is ignored.

like image 66
Álvaro González Avatar answered Mar 25 '26 08:03

Álvaro González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!