Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127765 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 F08521A00BC for ; Thu, 26 Jun 2025 23:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1750979935; bh=Iq1duX2aDScVKsFuuEfpdbLRsJ5oBaOLRsJhVT8v0W8=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=ZpYc/A3hFD7BGpWZ+uo11QPTkVlkzhFYpRCZOT1k20dhtLrUFDH2msVazbwu0cGzd hx+0eLSz6R4IrZFU+LSDsEKitoR8hMQafUbAcmMQFdO6WsV3Oif3zDdimJ5FEr4/1l V6qp6wauzgJFzna9S98plEZG+b2SPOaZCucEzHDAAudXLDfYIAiUT0QyqIUybqNmRB /88VfRelCVysci1isTfA/+LELs+Qo4NhPeLDhxSMjXCL8eh4OzQnhv6zs90weJHspS CGuvdBatj7QmeUFNFXoPlnOjuk7Hb3nVX3HYM14gtLV6u5NvviwJjwgB9RumR5NH6W U8q7VR6QCgUlQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DF0BC18006E for ; Thu, 26 Jun 2025 23:18:54 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, 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 mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 23:18:54 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-313067339e9so240126a91.2 for ; Thu, 26 Jun 2025 16:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750980048; x=1751584848; darn=lists.php.net; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=+b6FDol1+NiohWXQqT2d1I0+kEovdv4O0jVRgINUdO8=; b=FUzI4M8B9scEA5j/73564ogFStAY7D14LdAoH9x7rPjiQ9IeD0mUJzweQYzjO8UdWM Qx6jG8Yl98HKU9ATwjvptqOKoujBoG7fCtSwqxW4TcgxSnE2HOd0Ji5LOejOT8xLP/Ha kBM4qFsvZDwrhXYQYtCr7IWeMF34MljcAFF6WqiC+FWUludHSrAd9vuF1MikuIIni1cU rqyy3nPfu9KbUmxtOsMKYxkLZ+kQ3TRhWz/5YDBIp6yFh6Zuje9JxaeIxqbIFPQO8nw3 1h74E74OzqVMBNJ2V1naS/753oolYs2+Di2aNBkyrFB4eo8ESZSzEpQaRtG40Qmqnim6 itTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750980048; x=1751584848; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+b6FDol1+NiohWXQqT2d1I0+kEovdv4O0jVRgINUdO8=; b=Qhb77qolavI/DnCHA3hVuZUrWzYnU7W+lAvwkLHPcu5Ii1+VzfbqCYmZEmaKYt1nTq 0q30uQHVArjXl8D0cpmStujAhRE28nBgO4QjxkVa/hWS+7/z32LGk6DDz8DIlcK7Q/yG oxxpD6j+Kd5evs6epRNVWo3pqGwXbzQfBjABxY7i+HZoJs+tkqlC2qO54ky22ih8m3jP CtGL6WDhwsgrKQRdGFkqRfyjQD1x6pOpds4fs+jED8q1fcUxB3Ej3MAUrqy6cxF+Q5Cv t67Qaisd1T42AgdvPDPQrybennUcM6cYj5wgdTt5BOaKoVLgyu1Kzb5q9T9fRpakmOuM a3CA== X-Gm-Message-State: AOJu0YzP5aN9JxZw07OcQ1Qpxwd/+ZaAxPOP6IlbUtadmDNan121Wnh0 72z5ylb1Jo+q2MUHcr37xMQ4MqC69BwW7kPmnJbKXnZ+z3LB06N2edBzBTvLzVKt X-Gm-Gg: ASbGncti6K/zZjveQzLKEKcVFXmj40unOgbTPgva1g0OxrvgoPoclRTGT8jrVFNJf48 ZlCTkHrGz8oI7kvEn1jYk9OnB/84DWbzSYcUPLvw7gT4XvcS8AWUkwLie07isQoiLp71QsYEi2C QbKlHUhPiPnDbh+iK9C/n0D5AUGF/9Cctok1/WwwPQj9PhKeZZTpCmRumdIP10zsqiq7gWharaz 3W2uopGTbDFfbccBWrQxBY7MP7tfZFwG8rpkgrnFemY3M8vzfT8wOgPdzrhbhYMcyuGJkYIiAcy oxGlBMKRtvlVGGPlVt/pRSdTpvMFDLr+CC+FLFTUc8MYTOLMhqijJNI8m/dAUxqBQM1itw60oYk 5UiPKZePjBok= X-Google-Smtp-Source: AGHT+IHYOc6EPSQNZJ1sZsx6EZEktdTuYK/AjAxKs7xz9XN0T10JBIGaj7E+3SPCHHHNTxH2aWSk5Q== X-Received: by 2002:a05:6a20:7fa1:b0:21f:56d9:9ade with SMTP id adf61e73a8af0-220a18381cbmr485608637.9.1750980048395; Thu, 26 Jun 2025 16:20:48 -0700 (PDT) Received: from smtpclient.apple ([2804:c88:cafe:da69:d0d9:30ed:907e:42ff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74af541d233sm784247b3a.61.2025.06.26.16.20.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Jun 2025 16:20:47 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object-oriented curl API v2 Date: Thu, 26 Jun 2025 20:20:35 -0300 Message-ID: <08947F7B-7EC5-4349-9FEA-D0768695ACFB@gmail.com> References: Cc: internals@lists.php.net In-Reply-To: To: Rowan Tommins X-Mailer: iPhone Mail (22F76) From: deleugyn@gmail.com (=?utf-8?Q?Marco_Aur=C3=A9lio_Deleu?=) >=20 > On 26 Jun 2025, at 18:07, Rowan Tommins [IMSoP] wro= te: >=20 > =EF=BB=BFOn 26/06/2025 17:53, Larry Garfield wrote: >=20 >> 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. >=20 >=20 > 100% this. >=20 > Writing "$ch->setOptionInt(Curl\Option\IntOpt::ConnectTimeout, 30);" inste= ad of "curl_setopt(CURLOPT_CONNECTTIMEOUT, 30);" is mostly rearranging the p= unctuation deck-chairs on the ugly code Titanic. >=20 > Particularly when you can *also* write "$ch->setOptionInt(Curl\Option\IntO= pt::ConnectTimeoutMs, 30_000);" with the same effect. >=20 >=20 >=20 >> I realize that would be considerably more work to define all those method= s (I don't even know how many Curl has, as I rarely use it directly). >=20 >=20 > I believe there are 272 "CURLOPT_" constants currently documented in the P= HP manual: https://www.php.net/manual/en/curl.constants.php >=20 > So, I totally agree that we need a "set raw option" method to support some= of the more niche features. >=20 > But that long list is also exactly why we badly need helpers for common us= e cases - the manual page for curl_setopt has been at the top of the charts f= or number of user comments for years, because nobody wants to read the descr= iptions for two hundred options they'll never need. >=20 >=20 >=20 >> 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) >=20 >=20 > I think calling it a "vision for a high-level API" is making it sound far m= ore grandiose than what I suggested. What I suggested, and would still like t= o see, is a small number of additional methods, for setting really common op= tions in a more user-friendly way. >=20 > Looking at my earlier message, my finger-in-the-air number was even smalle= r than Larry's - a set of 10 methods, each covering a handful of overlapping= or closely related options. >=20 > A single "setHttpMethod" method would bring immediate value, instead of ch= oosing between CURLOPT_HTTPGET, CURLOPT_POST, CURLOPT_PUT, CURLOPT_NOBODY (f= or HEAD) and CURLOPT_CUSTOMREQUEST. >=20 > Adding more helpers in later versions is entirely trivial, but we could se= t the precedent with a first batch on day one. >=20 >=20 > The only other "high-level" API I see discussed in the previous thread is s= plitting the execute() method, for exactly the same reason as splitting setO= pt(): type safety. >=20 > public function executeAndReturn(): string > public function executeAndOutput(): void > public function executeToFile(Stream $fileHandle): void > public function executeWithCallback(callable $wrIteFunction): void >=20 > The CURLOPT_RETURNTRANSFER, CURLOPT_FILE, and CURLOPT_WRITEFUNCTION would t= hen not exist in the option enum(s), because there would be no way to make u= se of them. >=20 > Unlike the helper methods, that's one we have to decide in advance - it wo= uld be a mess to have those *as well as* a universal "execute(): ?string". >=20 >=20 > -- > Rowan Tommins > [IMSoP] I=E2=80=99m excited at just the discussion of a possibility for PHP to be ab= le to perform basic HTTP requests in a friendly way. Last month I worked on a= solution that involved an SQS Worker that do some work and then sends the o= utput back to the origin via a HTTP request that is passed as part of the me= ssage; basically a callback over the wire. However, running it on Serverless= as a plugin that makes no assumption about the project state, I couldn=E2=80= =99t use Guzzle or any composer library for that matter. I had to stick with= what=E2=80=99s available on Amazon Linux and Bref, which cURL is, but it=E2= =80=99s such an unpleasant experience to have to write HTTP requests like it= =E2=80=99s 2003.=20 I really hope some minor helpers can be added to this OOP version of cURL an= d I agree that it doesn=E2=80=99t need to be hashed out, perfect or even cov= er 270 cases. Just a simple GET/POST/PUT/PATCH/DELETE with a string body and= some headers manipulation would go 99% of the way already.=