是否可以在MySQL事务中运行整个PHP应用程序? [英] Is it ok to run whole PHP application in a MySQL transaction?

查看:111
本文介绍了是否可以在MySQL事务中运行整个PHP应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在MySQL事务中运行整个PHP应用程序?

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

是否有任何副作用?

我的意思是这样:


  1. 客户请求A.php

  2. < > start mysql transaction
  3. A.php - >执行并处理请求

  4. A.php - >提交mysql事务

  5. 将所请求的数据发送到客户端

  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


推荐答案

在一个事务中运行整个PHP应用程序,而是在一个单独的事务中处理每个请求的PHP脚本。

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.

但是由于这些相同的概念适用于基于纯SQL引擎的(存储过程)解决方案,没有特别的理由不在PHP中这样做。

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.

这篇关于是否可以在MySQL事务中运行整个PHP应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆