1

First of all I'm a newbie, so I hope you have patience with my existential crisis

I'm a bit confused... connection pools are only for application servers (Tomcat) and not web servers (Apache) ?

It only works in some languages?

I tried to do SQL transactions from PHP and failed.I know that it is possible to make transactions, but not to make them at the moment the user clicks the commit or rollback button to save points . That's why I wanted to use a connection pool, but I can't XD

I read that it is not possible in PHP, but if in JAVA , then I wonder the connection pool is configured in the language or in the server?

Asuna
  • 11
  • 1

1 Answers1

0

Connection Pool is a term which represents a cache of reusable connections. It is not necessarily implying an application server, it can be a webserver as well. It is definitely possible in PHP:

enter image description here

http://php.adamharvey.name/manual/en/mysqlnd-ms.pooling.php

You can create a connection in a PHP script and you will be able to reuse it without recreating it.

It is very important to separate the concept of a server from the concept of a language. A language is defined by its syntax and its concepts. Yet, abstract terms, such as the connection pool exist wherever the server supports it. One can write a PHP server that supports connection pooling and another which does not.

You can read about connection pooling on nginx, a well-known server that supports PHP:

https://www.nginx.com/blog/load-balancing-with-nginx-plus-part-2/

Further reading: https://www.php.net/manual/en/pdo.connections.php

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • Hello! I appreciate your quick response! So, As long as the server allows it we can do it, I try to make a pool of connections with Apache, unfortunately in the documentation that you left me or on the internet I can't find any reference script to do it, because Apache releases all the resources when the request is finished for the current requests So I am very confused if I can do it ... in this link says "There is no connection pooling in php" https://stackoverflow.com/questions/39753/connection-pooling-in-php Maybe I should switch to nginx and try to do it – Asuna Jun 15 '22 at 01:55
  • @Asuna that's a thread from 2008, things have largely changed since then. Basically you can persist connections while your PHP script is running in Apache or Nginx. Take a look at these examples: https://www.w3schools.com/php/php_mysql_update.asp (the PDO-based example is to be recommended). You can see a connection being created and an update being executed. You could execute another update using the same connection, without reconnecting. Skip the example to your MySQL credentials and some MySQL command that is sensible in your context. – Lajos Arpad Jun 15 '22 at 09:33
  • @Asuna and here is a MySQL transaction example: https://stackoverflow.com/questions/2708237/php-mysql-transactions-examples and here you can find a tutorial: https://www.mysqltutorial.org/php-mysql-transaction/ – Lajos Arpad Jun 15 '22 at 09:34