Bug #78930 [Opn->Nab]: PDO Sqlite not close connection after destruction (windows only)
| From: | requinix@php.net | Date: | Sun, 08 Dec 2019 19:12:51 +0000 |
| Subject: | Bug #78930 [Opn->Nab]: PDO Sqlite not close connection after destruction (windows only) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224133@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78930&edit=1
ID: 78930
Updated by: requinix@php.net
Reported by: julien dot boudry at gmail dot com
Summary: PDO Sqlite not close connection after destruction
(windows only)
-Status: Open
+Status: Not a bug
Type: Bug
Package: PDO SQLite
Operating System: Windows only
PHP Version: 7.4.0
Block user comment: N
Private report: N
New Comment:
Windows does not allow deleting files while there are open handles to it. Linux does.
Clean up the circular reference with gc_collect_cycles().
https://www.php.net/manual/en/features.gc.php
Previous Comments:
------------------------------------------------------------------------
[2019-12-08 18:39:30] julien dot boudry at gmail dot com
If I comment the line 17:
// $this->myContainer = $myContainer;
It's working.
--
Even if I add a destructor on Test class:
public function __destruct () {
$this->myContainer = null;
}
If not working too.
------------------------------------------------------------------------
[2019-12-08 18:25:51] julien dot boudry at gmail dot com
Description:
------------
Impossible to unlink an SQLite file after destroying his PDO object. Not reproducible in any
context, but happen with circular references.
On Windows only, PHP 7.3 and PHP 7.4.0 (not tested on lower versions).
Test script:
---------------
<?php
class Test {
public static $path;
protected $base;
protected $prepare = [];
protected $myContainer;
public function __construct (Container $myContainer)
{
$this->myContainer = $myContainer;
self::$path = getcwd().'/base.sqlite';
$this->base = new PDO
('sqlite:'.self::$path,'','',[\PDO::ATTR_PERSISTENT => false]);
$this->base->query('CREATE TABLE IF NOT EXISTS test (col_a INTEGER PRIMARY KEY
NOT NULL)');
$this->prepare[] = $this->base->prepare('INSERT INTO test VALUES (1)');
}
}
class Container
{
protected $myTest;
public function __construct () {
$this->myTest = new Test ($this);
}
}
$container = new Container;
unset($container);
unlink(Test::$path);
Expected result:
----------------
Not any output or warning and File bdd.sqlite destroy. On Linux it's working as expected.
Actual result:
--------------
PHP Warning: unlink(C:\php-script/base.sqlite): Resource temporarily unavailable in
C:\php-script\pdo.php on line 40
PHP Stack trace:
PHP 1. {main}() C:\php-script\pdo.php:0
PHP 2. unlink() C:\php-script\pdo.php:40
Warning: unlink(C:\php-script/base.sqlite): Resource temporarily unavailable in
C:\php-script\pdo.php on line 40
Call Stack:
0.4049 396904 1. {main}() C:\php-script\pdo.php:0
0.4073 398376 2. unlink() C:\php-script\pdo.php:40
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78930&edit=1