Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127777 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 D2C2B1A00BC for ; Fri, 27 Jun 2025 21:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751061441; bh=YZj+rzhqFMDUr2whjSpiYEsCdw/jwQ4NCd6rAIM7M+w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mqz4v4NKtsknNkQavmarc0WiRQWH0obEzP5/CwtpqPOkIvE6fZuVoDjU7rEqDlcsh 5G6Skf1m7P8ijdAr0H1zEJY90PX+MHJJzgjjEGFahQg3Xxv63HFnYGrjJ6kDN6YO2+ TieW0Ishorrys5Vp+WWyzb410aY7CcmFEh5jBCGQ4McKT1u6M0UNYKeckCwRtTRKL+ VA3iV1ZlB4sLPiVHjWBkglbquoRXxkAKrlivcFcitwqKL+/+KT6iuiP7t3P7CFendW oSTbkmYOE3rkFO4aVjTpss3DehEXk0kEuXA+5iut8VrT7eqPpyoEa0OJWAmeUB3p8e 15e+mNGJdqodw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9564C180041 for ; Fri, 27 Jun 2025 21:57:19 +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=-1.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,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 forward500d.mail.yandex.net (forward500d.mail.yandex.net [178.154.239.208]) (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 ; Fri, 27 Jun 2025 21:57:09 +0000 (UTC) Received: from mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net [IPv6:2a02:6b8:c43:4b81:0:640:447f:0]) by forward500d.mail.yandex.net (Yandex) with ESMTPS id D14DA6114B for ; Sat, 28 Jun 2025 00:59:00 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id xweBCfGLriE0-Au4QiUVm; Sat, 28 Jun 2025 00:59:00 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=php.watch; s=mail; t=1751061540; bh=YZj+rzhqFMDUr2whjSpiYEsCdw/jwQ4NCd6rAIM7M+w=; h=To:Subject:Message-ID:References:Date:From:In-Reply-To:Cc; b=JjFb/j63Q4VuMh6QdN4wlzeLHum0nl0dOmeiUBBgwwWnBr5z1+zide71j/3ll5UnE ma86zceg6f6Et1iVG+SUszR+7OcTmsX3HG5pCtXUR4m9A2ASKP+QrRca4hmaMjCdsE SNgitSAveSIK+w1XsBDw4zr+2LbFwEYJGVeEZ10k= Authentication-Results: mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net; dkim=pass header.i=@php.watch Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-60c93c23b08so524554a12.3 for ; Fri, 27 Jun 2025 14:58:59 -0700 (PDT) X-Gm-Message-State: AOJu0Yyni4CWEzlwd8mdWPxrqB1as5PdaofJvHJX/op9FLs7sjHromke JnYA2dGboT0S0yS7wqTdx0JPfigu3MKi02A2KwLfuJwAtz7487KNHK7omEBVX0TB2MnCsNr29Nx TJ1O0/6Wrg/am1tuAvyBMW66KqHnny/4= X-Google-Smtp-Source: AGHT+IEu7Tp8wxbfUX5NGU17zoECbQi3Uz/uajcj/1IwfuUQ+8q/TXWkr8TMMNJhGeggBe+ju374N/BfbnyGeDNVPRo= X-Received: by 2002:a05:6402:5108:b0:5fe:7b09:9e27 with SMTP id 4fb4d7f45d1cf-60c88b55d4dmr3563089a12.12.1751061538939; Fri, 27 Jun 2025 14:58:58 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 28 Jun 2025 03:28:00 +0530 X-Gmail-Original-Message-ID: X-Gm-Features: Ac12FXzSIIpeSFi1UzZG8sza7DwSkuwgfnH725uNBD4RegujBsuUaS0YuELNwng Message-ID: Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object-oriented curl API v2 To: erictnorris@gmail.com Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: ayesh@php.watch (Ayesh Karunaratne) > Hello Internals, > > I'd like to formally propose a restart of the original object-oriented > curl API RFC (https://wiki.php.net/rfc/curl-oop): > > https://wiki.php.net/rfc/curl_oop_v2 > > The prior RFC seemed to get positive feedback, with a small consensus > around wanting enum(s) for curl options. I've taken that feedback and > incorporated it into a new RFC, as I am not the original author, but I > am interested in making another potential improvement to the curl > extension. > > In a nutshell, this version of the RFC: > > - uses enumerations for curl options and other curl constants > - introduces a new Curl namespace > > I have not yet created an implementation PR. I realize that is > somewhat discouraged, but I believe that this should be relatively > straightforward to implement (there's also the previous RFC's PR to > build on top of). The implementation of this RFC as it is now will > likely be tedious, however, so I'd like to get feedback on the > enumeration idea before committing to the work. > > I've outlined one open question in the RFC, which relates to the above: > > - Should we organize the curl option enumerations by value type? Or > have a single enumeration for all curl_setopt options and another for > all curl_multi_setopt options? > > If others (including the original RFC author) are interested in > working with me on this, I'm more than open to that, so please let me > know. > > Thanks, > Eric Thank you for taking the initiative to work on this. It's long overdue, and the pattern we have now =E2=80=94 that a `CurlHandle` object i= s passed to functions =E2=80=94 is not as intuitive as calling a method on th= at object. However, I softly oppose this RFC in its current state and the way it seems to be going. I have pushed Curl and libcurl to some uncommon cases such as HTTP/3, DoH, the new debug callback (which I authored the PR for), IMAP, and a few other obscure tweaks. For all of them, the current `curl_setopt` worked, and the more I used it, the more I understood that having just a few Curl functions and a sea of Curl options is the least "presumptive way", regardless of the protocol and the options Curl provides. The extension is named `Curl`, because it's supposed to provide Curl functionality into PHP. It provides low-level functionality, but we should leave it to the PHP users to build the libraries that have fluent APIs. This way, we can have excellent purpose-built HTTP clients, IMAP clients, Tor proxies, etc, all built using the low-level functionality the extension offers.The HTTP client authors know the Curl options really well to build a secure and fast HTTP client, and someone else building an IMAP client can provide an intuitive API but still use the same underlying Curl functionality. I understand that your RFC does not propose a high-level API, and I agree with you that a high-level API will need a lot of discussion. There's a ton of Curl constants, and you are right that it could really use some organizing. The upstream Curl project has not done it, most likely because the options behave differently depending on the protocol, and simply because it's a lot of work and BC trouble to do so. I don=E2=80=99t think we can realistically have a meaningful discourse = on how to semantically group the constants into meaningful Enums. I'd also argue that if libcurl is OK with having a sea of Curl options, we should not be the one to group them. Grouping them by the expected value type is one way to do it, but as mentioned elsewhere in replies, now, the consumers of the API will have to figure out whether that one Curl option they always used belongs to `IntOpt` or a `BoolOpt`. It will help with `CURLOPT_SSL_VERIFYHOST` (which should be set to `2`, not `true`), but I don't think this level of type safety is all that useful for the trouble. To bring some numbers, we currently have: - 271 CURLOPT_* consts (https://php.watch/codex?search=3DCURLOPT_) - 78 CURLINFO_* consts (https://php.watch/codex?search=3DCURLINFO_) - 71 CURLE_* consts (https://php.watch/codex?search=3DCURLE_) + I sent a PR to add 41 missing consts (https://github.com/php/php-src/pull/13340/files) - 150+ constants for options such as protocols, HTTP versions, URL follow rules, etc. I think a more light-weight approach would be to: - Move all of them to the `\Curl` namespace. - Rename Curl options to `\Curl\Option` namespace, and rename them, so that `CURLOPT_SSL_VERIFYHOST` becomes `Curl\Option\SSL_VERIFYHOST` - Rename Curl error codes to similar `\Curl\Error` constants. - Have the `CurlHandle` object accept options, e.g. `$ch->setOption(Curl\Option\SSL_VERIFYHOST, 2)`. libcurl Easy handlers do not have a way to retrieve the option once it's set, so there will be no `getOption` either. - Make Curl throw exceptions, and never `false` on `\Curl\execute()`, with the Exception's error code and message mapped to the Curl error code and message. We will not need to bring over `curl_error` or `curl_errno` functions. Realistically, I don't think we can deprecate and remove the `\curl_*` functions any time soon, so this will actually add more maintenance work for php-src at the end too. Thank you. Ayesh.