Reputation: 8496
Does anyone know how php requests data from mysql?
If I have mysql in the same machine as php, does it open a tcp connection to the localhost on port 3306 or does it have some other way of getting the data?
Is it the same in linux and windows?
Thanks
Upvotes: 4
Views: 1911
Reputation: 23228
if available it uses a unix socket, otherwise localhost.
Note that even if you specify localhost in the connection string it will try to use the faster "unix socket" if available
Upvotes: 8
Reputation: 11625
PHP opens a connection to port 3306 is the server via TCP to allow data communication. Hence, you can specify which port to connect to in mysql(i)_connect etc, and why, you need to have firewall rules for mysql.
It is the same in Windows as Linux
So yes, TCP :)
EDIT: Revision, In linux, php looks to connect to mysql via /tmp/mysql.sock the tmp directory needs to have correct permissions.
Upvotes: 0
Reputation: 2693
Usually PHP opens up a local pipe found at /tmp/mysql.sock to connect to a local version of the server, unless you use an IP address in your connection string.
Upvotes: 3