Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127774 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 C64051A00BC for ; Fri, 27 Jun 2025 15:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751039876; bh=2THC/ERbm+yOt3ijVJAJp9EkMkh71k8YHuIL22tyMe4=; h=Date:Subject:To:References:From:In-Reply-To:From; b=C8PmXvyZJAYOhOXpMRlLX5hicsHWmk7rINuFAhI3XEVhQZ8FPGQq/YJgg4+m0TTbX MRT2P8PTwxbgOEI7mhHaHLyOoWcu5K61jJuRwKw0p3gszqsD5xCeLUCmcdIMnvcpW3 C8PJhCspDmeDfQkCMthEsQvF4Nf35IKMDqie1s8fceSRyULJJC4jP2xjl4N61qGbqZ YCwJ1t7XTsXfUxFhj3DZUHFvRLwgXWMYtjViEgjjB9tN2EbL7VfErJDL7283CijNFO 5xPZMlrVLK+fix1ay6SPAkTXGxVMb3g3vvNv+q2dXY4n89tmEoW1sfiGcjykPHei8A rWYm2mh3xm9pQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D60E018006E for ; Fri, 27 Jun 2025 15:57:55 +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.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, 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-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (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 15:57:55 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 446DB7A01DF for ; Fri, 27 Jun 2025 11:59:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 27 Jun 2025 11:59:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :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=1751039989; x=1751126389; bh=fpbaB9Kr66 +mg/7k3oDLrBLLtBFoURRqx60beE8Cofs=; b=IfYdGX+kf3IACwnhLXdlCg0bpB en+DB4QaccESp8yjWj9rCU2lS0Oi8OwQYtENmVG0eKGrWAkDHRI6UVc20/S39Tt4 5KcZJH8VaJ4IrX0Fk0jX2V6bFjHgs6+EC252dkp6nVU2kIcoxQKoFSpvualaZwCi UNCLSw/dmB5mFvG9SMdU9TKq7S9yENAIpRa3i/ntEmL3s8qct4TVjzPJBvbGY/nM QirY+Ny4vmMR+k4Bt1NbkHTHJCNyU7vB3ziAgGetEYuorP/orEvr1giNvAUzKqLs 1yEnbLgnJDfJp94mSATg55lnNp1lGJ3tEPVyzo8VAvKY3dgKsn7HZf/ay/bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= 1751039989; x=1751126389; bh=fpbaB9Kr66+mg/7k3oDLrBLLtBFoURRqx60 beE8Cofs=; b=d6dg9EN5bDCY6GankNO240pYbvdrc9WJbLsJElgB4x53bovi/0j ZAgrN6s0mXbUVfB8HijiVZcJqrMj+Wxg2t7jD6wKtN/Wb0h/ATmDTQNQ1wtlVqud LNunktVzskU0fPt0nsRcS1bwAfKdukUbGVVznfRWubB3H33bbaobqkuZ5wXH3Fhl 1Sjko23nGERm2KYLDX2fglF3EEDp5GHuQk0F8/QJRa9PjLo6g7SdsGbEgz3Uz8t0 a3akslbbZsDJbPWm3Je/vB+IET77qWG+XioOvDunLxDLjPEv1la5PpYlZGUgDC49 uyjQcTtW+AdOzYUOw0MiDZgN+iG9asWxYUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdefgeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucenucfjughrpegtkfffgggfuffvfhfhjgesrgdtreertddvje enucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhs ohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepheetleeiie fgueduieeuieffvdevheduueefkeejuefgffeftdeitdegtedtleetnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhphesrh ifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 27 Jun 2025 11:59:48 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------Jc0M4j76nHhh9hHiUNj6WC8V" Message-ID: Date: Fri, 27 Jun 2025 16:59:47 +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: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------Jc0M4j76nHhh9hHiUNj6WC8V Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 27/06/2025 04:51, Eric Norris wrote: > I can try to take a look at the curl options and do some github > searches to see if I can identify common patterns. I agree that > setting the HTTP method and timeout are good contenders. If someone > else wants to propose a list as well, feel free! For what it's worth, I grepped my work code base for "CURLOPT_", and grouped the results into the categories below. Some of these are definitely more "advanced" than others, and a lot could just be one helper covering the whole category. Really basic (already in the proposed constructor): CURLOPT_URL Setting HTTP method: CURLOPT_HTTPGET CURLOPT_POST CURLOPT_CUSTOMREQUEST Request body (despite name, handles both form data and raw string bodies): CURLOPT_POSTFIELDS Request headers: CURLOPT_HTTPHEADER CURLOPT_USERAGENT CURLOPT_ENCODING (deprecated in favour of CURLOPT_ACCEPT_ENCODING) Response body handling: CURLOPT_FILE CURLOPT_RETURNTRANSFER Response header handling (extremely fiddly; it would be AMAZING to have something like getLastResponseHeaders() returning an array): CURLOPT_HEADER CURLOPT_HEADERFUNCTION Auth: CURLOPT_HTTPAUTH CURLOPT_USERPWD CURLOPT_SSLCERT (there's also a CURLOPT_SSLCERT_BLOB) CURLOPT_SSLKEY Error and redirect handling: CURLOPT_FOLLOWLOCATION CURLOPT_FAILONERROR Timeouts: CURLOPT_CONNECTTIMEOUT CURLOPT_TIMEOUT CURLOPT_TIMEOUT_MS Cookie handling: CURLOPT_COOKIE CURLOPT_COOKIEFILE CURLOPT_COOKIEJAR Connection parameter tuning: CURLOPT_HTTP_VERSION CURLOPT_SSLVERSION CURLOPT_SSL_VERIFYPEER (common, but shouldn't be!) Debug output (like response headers, this is very unintuitive for PHP users; $ch->enableVerboseLogs() and $ch->getVerboseLogs() would be very handy): CURLOPT_VERBOSE CURLOPT_CAINFO CURLOPT_STDERR > If we were to go this route, I would suggest: > > public function fetch(): string > public function execute(resource|callable $out): void > > that is, one method to just return the contents of the URL, and > another to either write output to a file (including STDOUT, if the > user desires), or to send output to a write callback. That makes a lot of sense! I've never been very good at keeping names and sentences short :) -- Rowan Tommins [IMSoP] --------------Jc0M4j76nHhh9hHiUNj6WC8V Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 27/06/2025 04:51, Eric Norris wrote:
I can try to take a look at the curl options and do some github
searches to see if I can identify common patterns. I agree that
setting the HTTP method and timeout are good contenders. If someone
else wants to propose a list as well, feel free!


For what it's worth, I grepped my work code base for "CURLOPT_", and grouped the results into the categories below. Some of these are definitely more "advanced" than others, and a lot could just be one helper covering the whole category.

Really basic (already in the proposed constructor):
CURLOPT_URL

Setting HTTP method:
CURLOPT_HTTPGET
CURLOPT_POST
CURLOPT_CUSTOMREQUEST

Request body (despite name, handles both form data and raw string bodies):
CURLOPT_POSTFIELDS

Request headers:
CURLOPT_HTTPHEADER
CURLOPT_USERAGENT
CURLOPT_ENCODING (deprecated in favour of CURLOPT_ACCEPT_ENCODING)

Response body handling:
CURLOPT_FILE
CURLOPT_RETURNTRANSFER

Response header handling (extremely fiddly; it would be AMAZING to have something like getLastResponseHeaders() returning an array):
CURLOPT_HEADER
CURLOPT_HEADERFUNCTION

Auth:
CURLOPT_HTTPAUTH
CURLOPT_USERPWD
CURLOPT_SSLCERT (there's also a CURLOPT_SSLCERT_BLOB)
CURLOPT_SSLKEY

Error and redirect handling:
CURLOPT_FOLLOWLOCATION
CURLOPT_FAILONERROR

Timeouts:
CURLOPT_CONNECTTIMEOUT
CURLOPT_TIMEOUT
CURLOPT_TIMEOUT_MS

Cookie handling:
CURLOPT_COOKIE
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR

Connection parameter tuning:
CURLOPT_HTTP_VERSION
CURLOPT_SSLVERSION
CURLOPT_SSL_VERIFYPEER (common, but shouldn't be!)

Debug output (like response headers, this is very unintuitive for PHP users; $ch->enableVerboseLogs() and $ch->getVerboseLogs() would be very handy):
CURLOPT_VERBOSE
CURLOPT_CAINFO
CURLOPT_STDERR



If we were to go this route, I would suggest:

public function fetch(): string
public function execute(resource|callable $out): void

that is, one method to just return the contents of the URL, and
another to either write output to a file (including STDOUT, if the
user desires), or to send output to a write callback.


That makes a lot of sense! I've never been very good at keeping names and sentences short :)


-- 
Rowan Tommins
[IMSoP]
--------------Jc0M4j76nHhh9hHiUNj6WC8V--