gpt4 book ai didi

php - PHP 的 SQLite3Stmt 类会导致锁定问题吗?

转载 作者:搜寻专家 更新时间:2023-10-31 20:39:51 25 4
gpt4 key购买 nike

<分区>

我正在运行 PHP 5.3.3(CentOS 6.5 中的最新版本)作为带有 Prefork 的 Apache 模块。

我发现如果脚本以某种方式耗尽时间或内存,SQLite3 数据库将永远锁定,直到 Apache 重新启动。

可重现测试:

// Open a connection to the database.
$db = new SQLite3('/path/to/test.db');

// Get a reserved lock.
$db->exec('BEGIN IMMEDIATE TRANSACTION');

// Construct a prepared statement SQLite3Stmt object.
$st = $db->prepare('SELECT value FROM sometable WHERE key=:key');

// Emulate the script running off the rails while calling the prepared statement.
while(true)
{
$st->bindValue(':key', 1);
}

如果您运行此脚本,它当然会耗尽执行时间和/或内存。然而,从那时起,数据库就被原来的 Apache 进程锁定了。在 Apache 重新启动之前,任何脚本都不能对数据库进行另一个保留锁定。

PHP 不应该在脚本终止时关闭数据库连接吗?这是PHP中的错误吗?将其作为 FastCGI 进程运行可以解决吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com