duanli9930 2017-03-18 18:01
浏览 77

在事务运行时防止其他应用程序中的超时

I have a PHP script (which uses Eloquent) that is automatically run every day and makes hundreds of thousands of insertions and deletions on a table.

To improve the performance of the script, as well as to prevent inconsistencies occurring in other applications that use the same database, I'm using a transaction like so:

DB::transaction(function() use ($flights) {
  Flights::where('manual', false)->delete();

  foreach ($flights as $id => $value) {
    $count = Flights::where('id', $id)->count();

    if ($count !== 0) {
      Flights::create([
        'id' => $id,
        'value' => $value,
        'manual' => false
      ]);
    }
  }
}

However, any operations from other sources (such as the web application portions of the application) have timeouts when performing select queries on the database.

How can I prevent this from happening?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失