0

Hello I have service which works in transactions, it's communicating with remote API and I want to log every request/response in this API, but if main transaction rollback, any logs will be rollbacked too.

What I think is to clone DBAL connection. Will it open second connection with no transaction where I can insert with no fear of rollback ?

And is there any other way to work-around this?

CappY
  • 1,510
  • 1
  • 17
  • 32

1 Answers1

0

You could make your logging table a not respect the transactions by using a non-transactional storage engine such as MyISAM for that table only.

This is similar to an autonomous transaction in Oracle, and was suggested in this question.

Community
  • 1
  • 1
stwalkerster
  • 1,646
  • 1
  • 20
  • 30
  • I was thinking of second connection, but I wonder if just clone $DBALObject will open second connection or keep reference to first one. I will have to try. – CappY Mar 06 '15 at 09:51
  • I just tried: clone $dbalConnection; DOES NOT open connection, it's reference. Here is my work-around: `$secondDBAL = \Doctrine\DBAL\DriverManager::getConnection($firstDbal->getParams());` – CappY Mar 06 '15 at 10:17