amphp / mysql

An async MySQL client for PHP, optimizing database interactions with efficient non-blocking capabilities. Perfect for responsive, high-performance applications.
Other
358 stars 63 forks source link

How to release back my connection to the pool? #48

Closed shtse8 closed 6 years ago

shtse8 commented 7 years ago

I got a connection from the pool for doing transaction. How can I release it back to the pool after commit?

for the current design, it seems I need to close that connection myself. because the connection I got is removed from the connection pool.

It seems the development of this project is being inactive. But I have to say, this is an important project for making PHP better to compare with node.js. Thanks for amphp, I can code event-driven now. But the supporting library is so few. Cheer up. Make amphp better. yield syntax is far much better than evil then.

bwoebi commented 7 years ago

The reason why this currently is not possible, is that you could have changed the internal state of the connection compared to pool. (e.g. have chosen another database or issued some SET commands).

I was probably overly cautious here and we really should add a way to allow that.

And no, the project is not inactive, it's just one of many amphp libs. We're always replying to issues and also fixing things as necessary.

shtse8 commented 7 years ago

For the state, I think programmer should handle it well. If we have changed the state, we should reset the state or close the connection but not release it back to the pool. It is hard for us to handle the state perfectly, we need programmer to take care of it.

kelunik commented 6 years ago

Transactions should use a dedicated API, all other things shouldn't return connections to the pool, as we can't know the state of these connections and things are probably going to break in subtle ways, which is hard to debug then. I think transactions have been implemented now, otherwise #24 is the issue to track that.