Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127764 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 080331A00BC for ; Thu, 26 Jun 2025 21:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1750971771; bh=YM/Y1R0stx1nDL5c7nLPVaKlXh2S/7uZI5Mo7X9GKy0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=I+2oKXEZQVnR1I9UqWBBAsdWGKqeu6a6y4GbaEqzuAl/h0oG+Sh25d40fmFoLLQ3A iFmrKyAhHInQgnwX1TJpRJ8JNfIFGhIVL+zoXCm1qH9oHw73pzkB7O2g0HLjvreF9J tHjfl+QnFQk2nJiY2qxaQ65wk07vn1MJ2mXVRUfsryup90HY8GwK52CaQTx2AFFCHc Wmawk43uwO1Hn+Xr+0/67lwOJnY48OiOVB9Eipqvl6NJESDl0xKFO3O8lJqTSEXfRm DBrzNzwn4SA8lNxN+Sco+OU/QEdd2f8ve2vcmGukXT6pBPdawE2pigcVVcSdvxjvvV jUNeuOtuR4w7w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B4F4618006E for ; Thu, 26 Jun 2025 21:02:50 +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=-0.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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 ; Thu, 26 Jun 2025 21:02:40 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id CF6427A0072 for ; Thu, 26 Jun 2025 17:04:34 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 26 Jun 2025 17:04:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=1750971874; x=1751058274; bh=72XkrlY9ui58Z3T5Uzs0oGDV9lDelg1HPL8pil4KPuI=; b= f66L0eUs7Fw5jQ4Cd7cLemBGEXXdcSZnWwPlFk70GnIlE7C943nwcHqX3YMsoz5e YmGq/aqKzavAHxrEXIWCFRZ95BwZIEDHl0jQBrOS/SrIiPDHuA9khxawWjHb0E+v 3/GuYaZb0O2rZ4UZpYO7dJUvC5g0+W8DyvhDY68XxBH+mLe8VO9vuYPnGS5Tq/zR nbc82k+EBtKBRaI2dfo1JFpK29a8U7mSyYXvfTAHcTkRdWxL277uG1jC/nVrhpnO 0xWKOrKmFpPJscskqmLBDMdAqc9Tt3ApUBXKMI6ozT/ibDfmXYEacxUzfIsU5+46 TzmVrOfqxhQbjHrbaXhTzg== 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=1750971874; x=1751058274; bh=7 2XkrlY9ui58Z3T5Uzs0oGDV9lDelg1HPL8pil4KPuI=; b=ezCUGJMpDuTuvpfSi qYYEYsS1afSReRc+7FHCFdvZnTyGBDO5h9L7MIMWPi+MP5vzhUsChecVPqv+8GMd 0iDQsuGf1fEC0j9NzEwj4aE7WYbMDDxtbUvNS8/vxjCSB2cOMmi4FBze+FN7L7ro 4HJeEqCNUOAPX1D95aAYmE+STw0pNcJL3/vDdGs6qOpp8sABmnEkjU1Ym/cES/5R e0/HxWuX+Ie7nteTNA9Z9EQJRVMLQecgYlIzT3k/GyoNZqfP5nUIsU1Pn56iaCC1 xMUT4HUaAgRH+j+4AZ5GF6o0d19tvsUw7C/Ru8gUloWXTgBrAlZQvGnUFEh3ASKx sFUgQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvd ejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhm shhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeffleekhf etkeffheethfffueeileffgeffkeduvdfgjeetudejteeuueeiieffkeenucffohhmrghi nhepphhhphdrnhgvthdpvgigthgvrhhnrghlshdrihhonecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhphesrhifvggtrdgt ohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 26 Jun 2025 17:04:33 -0400 (EDT) Message-ID: Date: Thu, 26 Jun 2025 22:04:32 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object-oriented curl API v2 Content-Language: en-GB To: internals@lists.php.net References: <22a4327d-b27d-4e24-b07a-ae380fe8a0c4@app.fastmail.com> In-Reply-To: <22a4327d-b27d-4e24-b07a-ae380fe8a0c4@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 26/06/2025 17:53, Larry Garfield wrote: > Now here's the big one: Using enums rather than a bunch of constants is a good change. However, I feel like it doesn't go far enough. 100% this. Writing "$ch->setOptionInt(Curl\Option\IntOpt::ConnectTimeout, 30);" instead of "curl_setopt(CURLOPT_CONNECTTIMEOUT, 30);" is mostly rearranging the punctuation deck-chairs on the ugly code Titanic. Particularly when you can *also* write "$ch->setOptionInt(Curl\Option\IntOpt::ConnectTimeoutMs, 30_000);" with the same effect. > I realize that would be considerably more work to define all those methods (I don't even know how many Curl has, as I rarely use it directly). I believe there are 272 "CURLOPT_" constants currently documented in the PHP manual: https://www.php.net/manual/en/curl.constants.php So, I totally agree that we need a "set raw option" method to support some of the more niche features. But that long list is also exactly why we badly need helpers for common use cases - the manual page for curl_setopt has been at the top of the charts for number of user comments for years, because nobody wants to read the descriptions for two hundred options they'll never need. On 26/06/2025 18:21, Eric Norris wrote: > I know that in the prior discussion, Rowan Tommins had a vision for a > high-level API (https://externals.io/message/122371#122424) I think calling it a "vision for a high-level API" is making it sound far more grandiose than what I suggested. What I suggested, and would still like to see, is a small number of additional methods, for setting really common options in a more user-friendly way. Looking at my earlier message, my finger-in-the-air number was even smaller than Larry's - a set of 10 methods, each covering a handful of overlapping or closely related options. A single "setHttpMethod" method would bring immediate value, instead of choosing between CURLOPT_HTTPGET, CURLOPT_POST, CURLOPT_PUT, CURLOPT_NOBODY (for HEAD) and CURLOPT_CUSTOMREQUEST. Adding more helpers in later versions is entirely trivial, but we could set the precedent with a first batch on day one. The only other "high-level" API I see discussed in the previous thread is splitting the execute() method, for exactly the same reason as splitting setOpt(): type safety. public function executeAndReturn(): string public function executeAndOutput(): void public function executeToFile(Stream $fileHandle): void public function executeWithCallback(callable $wrIteFunction): void The CURLOPT_RETURNTRANSFER, CURLOPT_FILE, and CURLOPT_WRITEFUNCTION would then not exist in the option enum(s), because there would be no way to make use of them. Unlike the helper methods, that's one we have to decide in advance - it would be a mess to have those *as well as* a universal "execute(): ?string". -- Rowan Tommins [IMSoP]