Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90774 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30441 invoked from network); 21 Jan 2016 14:32:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jan 2016 14:32:41 -0000 Authentication-Results: pb1.pair.com header.from=gabriel.zerbib@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=gabriel.zerbib@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.50 as permitted sender) X-PHP-List-Original-Sender: gabriel.zerbib@gmail.com X-Host-Fingerprint: 209.85.218.50 mail-oi0-f50.google.com Received: from [209.85.218.50] ([209.85.218.50:35714] helo=mail-oi0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/54-09073-80CE0A65 for ; Thu, 21 Jan 2016 09:32:40 -0500 Received: by mail-oi0-f50.google.com with SMTP id p187so27122278oia.2 for ; Thu, 21 Jan 2016 06:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=UU2omTPGKxnGiYQfWGpjGghRKGCMkGZxqRB0Dv424k8=; b=az/ovwQ+oLk/wN6Em9dHS5gpj4T0mrXaEZBrVHZMVyfYjBRrqTN7oucL/+hkkzezEj pveHD/jjDIyQ+NA+iPiGFgenP7UgW4txyJzGpxqp10Lqi9WnGRC5FoViyZr28RSQR/Vc 8FnOi4bSu7w7rZNHJ8gTISt94Ip8GECnUMxYEU4UVy+40Hp/0fbKDQeKTICAogspPWve bW25T/Rr9KyGih+fgcxTKXePYrL19jSCMgle2TXvPmGcuTFm/cFq1AmHTV0csFkhsdoq jbhOHutOvgL7CNsCYhUYJKVB6oVaX5RVUNfUinjJEFbta2N32s3Jsa1J3avzo0YYyWCu IeWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=UU2omTPGKxnGiYQfWGpjGghRKGCMkGZxqRB0Dv424k8=; b=N6TP1fNK00q+9nVmixwfV9hHlQ+M5IC+c3AYEnf2r7v2eAt9T4Kb2S01Bwv0zQaz82 e0pxQiwfJsFmBd0peSQRhQDvwathK7cEuJjS5f0fQfYAmmwQ4IWk2p+5OeHYEPaGip9w GJg10XfakVZs2ecap6j2Md3sui9MGgBoFcxqCT9sv9hQTF3b4rmy6Yb1mpQra3Z7uIbW nxbxGHT8nXm7SMNeGpJSEHN5v+rzBSOpr8Qa/4n1SRqFaSCd0WUSfj23C7pUFjVTQchG ivHjLag/E/OFQ0pCsioxkJb3H/gM2StBCvtT63gXrwu7DlyzljBUcH8SyVAsK/g7q99m vbgA== X-Gm-Message-State: ALoCoQmG3fCNOCL2ti9ZmaXmZjFiopws5MastsIONPCjHgRGJuqEZP1bFJL4Cqh25nEkIJdjN2oqA4IyZb+KnSXT/utff6DFSw== X-Received: by 10.202.94.67 with SMTP id s64mr31478395oib.65.1453386757308; Thu, 21 Jan 2016 06:32:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.202.69.2 with HTTP; Thu, 21 Jan 2016 06:32:17 -0800 (PST) Date: Thu, 21 Jan 2016 16:32:17 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a113d54486408510529d8f9f5 Subject: PDO Close Connection From: gabriel.zerbib@gmail.com (Gabriel Zerbib) --001a113d54486408510529d8f9f5 Content-Type: text/plain; charset=UTF-8 Hi, list! This is my first email to this mailing list, so please pardon me for misuse of the traditions you may have here (formatting, phrasing, etc.). Maybe this has been discussed in depth earlier, but: I want to ask if there is an explicit reason for not giving a "close" instance method in the PDO class. The Web is full of wrong disputes about why one would want to explicitly close a PDO connection, since it is auto-released at end of script life-cycle. Of course this is wrong, because among many other use cases, for example a long running script (daemon-like) may want to free a DB Connection slot when they know they have to sleep for some time. The manual says that one has to assign to null, the variable retaining the PDO instance. One also has to null out all the variables holding a statement coming from that PDO instance). IMHO this is not good practice enough, especially given the way many PHP developers (mis)understand reference counting and variables. $a = new PDO(...); $b = $a; $a = null; This above snippet will not close the connection when assigning $a = null; (at list not until PHP 5.6 incl). In an application made of dependency injection, closures and many levels of function calls split over many files, it is virtually impossible to keep reference counting mentally, and you mostly end up never knowing what other component of the application still retains a reference to the PDO object. And yet, in some use cases, you still know that you want to release the connection before going to sleep or doing a lengthy operation (which might anyway cause a "Sql server has gone away", so you're better off not occupying a DBMS connection slot for nothing during the lengthy operation. I think it could be recommended to export a "closeConnection" method. I would be happy to know what people think (and pardon me again if the debate has been conducted already : please guide me to the corresponding literature?) If it is of any interest, what would be the next step? For me to open an RFC? Thanks, Regards, Gabriel --001a113d54486408510529d8f9f5--