How PHP interacts with MySQL on a single server

Does anyone know how php is querying data from mysql?

If I have mysql on the same machine as php, does it open a tcp connection from localhost to port 3306 or does it have another way to get data?

Is it the same in linux and windows?

thanks

+3
source share
3 answers

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 a faster "unix socket" if one is available

+8
source

PHP , /tmp/mysql.sock, , IP- .

+3

PHP opens a connection to port 3306 - it is a server over TCP to allow data transfer. Therefore, you can specify which port to connect to in mysql (i) _connect, etc., and why you need to have firewall rules for mysql.

This is the same on Windows as Linux

So yes, TCP :)

EDIT: Edition. On linux, php looks for a connection to mysql via /tmp/mysql.sock. The tmp directory must have the correct permissions.

0
source

Source: https://habr.com/ru/post/1716341/


All Articles