Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128747 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 31B191A00D3 for ; Tue, 30 Sep 2025 15:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1759246768; bh=WxEdbmlGAP1X3jNcZdzVOrI/WIXgODRBpP46clAbKQY=; h=Date:From:To:In-Reply-To:References:Subject:From; b=ELYC4ZypUGg9dh8EQrHJpTZKM8JLkYjF8RcIbEMJRIgSURIl2Kbxy/QbYjTAV8u/u 8RCILbBvtNYt4v1gnYFYCTiqT6E0XDfbY18lseK98ILncSAJPevtaCGBGszIOHLaca c5eFKE5007tuJdHhXv5pS8OpOEhoot4/vSLF/anP8IdM7XN7K5ivAnOvcuFml1sHIH GrRgQIMGqDupjt6sjp5IRsInlcShx1uoxGu+lIHNupw4G9YkuTFNQ8NeUM/XXCruLh dEbL/sQkXhJrpBCz/eaC+wj0U4srGAhN5DNsXWEg3SM+4SqxOSHCSrcG82ijNcRYJN 413mPIxhv4W3w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 462641804D2 for ; Tue, 30 Sep 2025 15:39:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 30 Sep 2025 15:39:22 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfout.stl.internal (Postfix) with ESMTP id BDBB11D00093 for ; Tue, 30 Sep 2025 11:40:41 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Tue, 30 Sep 2025 11:40:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1759246841; x=1759333241; bh=Q3tZWIVX1vOdUA45+QEwv a89d5UevoWmaL193Gfn1sA=; b=RlgxvMs1EC06JtzbryLJf1SntAvgaaZnSTnvq w8c7V7wI1dk/o6/8wHirFrUSWfTpTIHTWuEsLaPmMBPwvD0vEqDKbbcdLPwpbb7r l6N6FOscN1RthXvuwx3/2o+zak7O6obD0QHF9M8yEqyL2qEClByN0Kzlt+LGHrTK Rs2TL98u/qJDciyxswfjvzcpkwAq4ER8gr24ZEe9G5UiuTaUGTAC732Nk7sFM9qw ixrznRTgFhKKZxMzALTX/NJBpVb40A0wHP2OpkDduOtj0V2RLVWX4++TOKHxgXo6 A3eUAoGuPKYONWyQML3Q9aVQv/RzG9U7jYWYi4rgthuGiHlWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1759246841; x=1759333241; bh=Q 3tZWIVX1vOdUA45+QEwva89d5UevoWmaL193Gfn1sA=; b=YHLNc8VVAOVfemRPo WxitM+MiDmfSB+9u6EPStC41RwH3SodJDEBP0wxew7Du+8a6OBHosIL2nBvu+wVw L35w3ugjnGWkzapW1PEtNzzTOCwVCN9b5vo2S4jdH0lAVfUkdA+tBaE0/U7IdGHh 4d9Uqqvnad5KQk5gymhpMVJ+Ji35NfyKel34J8MRdI3ExC3CYiG8E9fTnq5EZwxc o0rwr+1+XFb+gNtwZ67FBBcro3UDn9jIlTa8XmVITD+75H1sv80st5KTDB/6xLCh m6tId9Ie+xcBl1hLebJDPz9muH0EW3tQzg/HnjLkZ2c3hUjBKUnyyliIuJwJInAP yDnfQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdekuddvvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhepudegvdelgfeugeehfeejteffudevleethfefgeejffffleeg tddtveekgeekudfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphht thhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhsse hlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 3ECE0700069; Tue, 30 Sep 2025 11:40:41 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AVtkA8y9rfU3 Date: Tue, 30 Sep 2025 10:40:21 -0500 To: "php internals" Message-ID: <4ddd9a25-47b8-4a2b-ad93-e93f8f33922b@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [Discuss] Add PDO disconnect() and isConnected() Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Tue, Sep 30, 2025, at 10:13 AM, Kamil Tekiela wrote: > By foot gun, I meant that when such a method exists, the developer can > never be sure that the PDO object is in a consistent state. As long as > the PDO object is accessible, closing it in one place in the code > means that there exists another place in the code where the object is > accessible but unusable. This is what gets so many mysqli users. > > Another issue is that if you call disconnect on PDO object, but you > still have PDOStatement with unfetched data, you silently lose the > data or get an exception. This situation is more difficult to > accidentally arrive at, but still possible. You also lose the ability > to call methods such as PDOStatement::execute(). This is not possible > today, but by adding disconnect method we introduce a way in which > this is possible. > > PDO isn't a new extension. It has done well without such a function > for many years. Maybe there are legitimate use cases for this, but > there are also alternatives. Pretty much every time I hear the > argument that it would be nice if PDO had it, I can reply with: you > can just design your code in a way that doesn't need it. > > The disconnect method isn't needed for long-running scripts. PHP will > disconnect automatically when it determines that the connection is no > longer needed, and only then. It's the responsibility of the developer > to ensure that they don't keep variables around that aren't necessary > anymore. I generally agree that there's little value to a disconnect() action; unset($pdo) is already sufficient. What would be valuable is easier RE-connection logic. Either PHP or MySQL may terminate an idle connection, which is a concern in long-running processes (Queue workers, ReactPHP, Franken, etc.). Tools like Doctrine have built their own refresh logic in, although they're not always consistent with each other or obvious to use. Having some kind of reconnection logic built into PDO that "just works" would be very valuable. What that would look like, I'm not sure. Just spitballing: // After X seconds, drop and reopen the connection the next time it's used. $pdo->reconnectAfter($seconds); --Larry Garfield