Php Mysql PDO connection on localhost by ip

Asked

Viewed 428 times

1

I have a PHP/Mysql system in which I connect via PDO on the "localhost" host, but I will need to put the IP of the server "xxx.xxx.xxx.xxx" instead of "localhost", the system works but very slow. I don’t know what it might be, both apache and mysql are on the same machine. Any suggestions?

  • Let me try to understand, in this case the speed test is being done locally, or on an external server?

  • I am testing externally, but the speed difference is noticeable. I have run a test now and locally there is no speed difference.

  • Because then you have to see the connection, the hosting service, if it’s going well at home...

  • It’s on its own server that I set up, so its local ip is like 192.168.1.15 ai on Pdo I pass this ip to connect to the localhost instead. Works but too slow

  • Right, but what’s your connection to it, what kind of cable you’re using... and the server conf, the cpu, the network card.... You have to put everything tim tim by tim tim, to be able to evaluate.... The configuration, the OS... QQ that talk is a long shot... You can hit an innocent...;)

  • Like this depending on the cable that is using the board to correct, but it’s been a while... This is one of the possibilities....

  • The BD consultation will be faster local because the two services are working on the same staff. In my opinion, I think the problem is not in the way that it is making the connection of the system to the database, but in its data bandwidth server. I advise you to add/exchange TAGS for something more server related.

  • As they are on the same machine you do not prefer to connect the socket?

  • I think it’s unclear. Apache and Mysql are on the same machine. Php connects localhost, the ip of this same machine is 192.168.1.15. I changed the configuration instead of informing "localhost" to the PDO I am informing the IP 192.168.1.15 which is the "localhost" itself. But it gets slow. I only have a machine, there is no other server. It was clear?

  • I’m making the connection like this: . new PDO($this->dbType.":host=localhost;dbname=".$_SESSION['cliente'], $this->user, $this->senha ... . Ai changed to: . new PDO($this->dbType.":host=192.168.1.15;dbname=".$_SESSION['cliente'], $this->user, $this->senha, ...

Show 5 more comments

1 answer

2


I managed to solve my problem.

In Mysql settings I added:

skip-name-resolve

Stay right where you need to be

Browser other questions tagged

You are not signed in. Login or sign up in order to post.