Is it ok to run whole PHP application in a MySQL transaction?

早过忘川 提交于 2020-01-06 20:16:48

问题


Is it ok to run whole PHP application in a MySQL transaction?

Is there any side effects?

I mean something like this:

  1. Client requests A.php
  2. A.php -> start mysql transaction
  3. A.php -> execute and process request
  4. A.php -> commit mysql transaction
  5. send requested data to client

回答1:


I would not call this running the whole PHP application in one transaction, but rather a PHP script that treats each request in a separate transaction.

That is fine, as long as you are aware of transaction related concepts, such as locking, deadlocks, starvation, ... In essence, you should like in any other environment not lock database objects longer than necessary, prefer fine grained row locks over full table locks and protect your database against deadlocks.

But as those same concepts apply in a pure SQL engine based (stored procedure) solution, there is no particular reason not to do this in PHP.



来源:https://stackoverflow.com/questions/35525208/is-it-ok-to-run-whole-php-application-in-a-mysql-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!