Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111538 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99367 invoked from network); 15 Aug 2020 15:37:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Aug 2020 15:37:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 71DC51804AA for ; Sat, 15 Aug 2020 07:38:07 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RDNS_DYNAMIC,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from qq.com (out203-205-221-235.mail.qq.com [203.205.221.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 15 Aug 2020 07:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1597502280; bh=tpwuyDnCQPqPdEQGn5lBvG8ePyUjd1w+R+QQC4Q+mz4=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=M2eqX6ViFLXlYodIiVaAD6f0NGPsyh0ZG5XLYAJCaEu2ayZBBp2cqKDZLHifDBjEM C2KS8aagSAlIw7cmeh8c39qvKKoX7nGPUtZX4QhE8yW0w7qllVh3WKHtKSmj8KrZ9C +Zc6NZIkgn4KszwSpAYLdRmt13aFdxNRjDsX+WZI= Received: from [127.0.0.1] ([111.198.225.237]) by newxmesmtplogicsvrszb5.qq.com (NewEsmtp) with SMTP id 97B264DC; Sat, 15 Aug 2020 22:37:59 +0800 X-QQ-mid: xmsmtpt1597502279tjszs0p30 Message-ID: X-QQ-XMAILINFO: MZDAXiv8lLL6hjgUh2XP/ocgrDEMmDwn+o9rjBA00pgOOYl55ZLYTsk0sAyuu4 R3xSZhVC6GdikLY7msksjN+oHd/3HBQStSHUcvDTUlDoUiv5F08XeVTYJteS3T1PDPUbdpnWZh+p mE9Gols2pvzFbTtK1riULgzXkXe2mkmTl/ALSNv/6rt9A0sGpcAAUYy3NDgmZoXZ0bSElcaZK8MC mVqDLXM9EJgahgEftAON1mmnXpmoEFKAASoY+guRr8fQgeo+XZU3V2gASK6xqUMgPkE7D/0wJm6O AHQYtIXYAFqaTsCSRy0Whgt6/h2wIT//Tm7H4f6o9xUxcZOihFNX9lJ1lMhU4e58SNf+7g2gnI5z WH/Fy3SaN6ec+FLAWL0+GDoXkse1QgtyHHlmw6ZRsprw4ORtqt8wF3CM4sEwDO9Uz16YEUFqR0mt JBffsya+s4HORRTi4zHkZmk8ZTsaFQterRhonQJ4z5EEf8EOGoRgQwftX7foE/Jkcf+ov//M8t5P HcGhBuA1Znc8VOvOjkoWZe+gJRClWYFERzW/nvqDr9CshYh5L5myVjsY9/gY+3PdPKm17L5EN0bb mwVoyarKuFKhqvEgHFT3eLh+U9cseqSZpLrBjC1ZAv4C9MvGvgaBDiuz5h2/fgEOJoXkVNWnyDDq Q/kilNbp7+zazQsu89vlD3pdsl9Pl4YpFWIk5DZ6fv3fAJilXbboFSP92tQc1LgIZWIVFWqbuxR1 swaTvVhui9dPk= Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) In-Reply-To: Date: Sat, 15 Aug 2020 22:37:59 +0800 Cc: PHP internals Content-Transfer-Encoding: quoted-printable X-OQ-MSGID: References: To: erictnorris@gmail.com X-Mailer: Apple Mail (2.3608.80.23.2.2) Subject: Re: [PHP-DEV] Proposal: Add PDO::checkLiveness method From: twose@qq.com (twosee) > 2020=E5=B9=B48=E6=9C=8815=E6=97=A5 =E4=B8=8A=E5=8D=882:16=EF=BC=8CEric = Norris =E5=86=99=E9=81=93=EF=BC=9A >=20 > Hey internals, >=20 > I've submitted https://github.com/php/php-src/pull/5935 as a way to = expose > an underlying PDO driver's check_liveness function to userland = scripts. > Often advice given on the internet is to issue a no-op statement (e.g. > SELECT 1 FROM dual), but this adds potentially unnecessary overhead = and > latency. Using the PDO driver's check_liveness function offers a = lower-cost > way of ensuring the connection is still alive. >=20 > As noted in the PR, I am not tied to the method name, and open to any > suggestions to making the PR better - I'm mostly interested in the > underlying concept. >=20 > It appears the test I added is currently failing for pgsql. I didn't = have a > test setup for that on hand but will look into it if there is positive > feedback for this PR. >=20 > Relatedly, I've also submitted = https://github.com/php/php-src/pull/5947 as > a way to potentially improve the mysqlnd driver's check_liveness = function. >=20 > Thanks! >=20 > Eric Norris Hi, I am the author of Swoole (https://github.com/swoole/swoole-src), I = have a little network programming experience, the following is my = personal opinion: I suggest not to check it, let it throw an exception (PHP8 has used = exceptions as the default error reporting way). checkLiveness() is not cost-free, it will also cause redundant system = call overhead, In fact, it has been heavily abused. I noticed that many = PHP network programming implementations do not care about the overhead = of system calls, such as constantly using recv(MSG_PEEK) to check the = connection before new requests, this is how checkLiveness() works. This = will cause severe performance degradation because failure is always = unexpected. And it even can't guarantee that the next call is successful, the = connection may be reset after check. What can you do if you noticed that the connection is disconnected? = phpredis checks the connection before each request and tries to = reconnect because the redis connection is almost stateless. So in = phpredis, it makes some sense to do so (phpredis will retry 10 times = when the connection is down, but this may be bad when the server is = busy). But MySQL can't do this, the context of it is too complex, let it throw = an exception, catch it, and start from the beginning again is the best = and cheapest way to solve it. All in all, let it fail and try again, the overall performance will be = better than checking before calling it every time, so I don't think this = API is necessary. Please don't use it, it will only make your program worse. Regards, Twosee