# [PR #22159] ext/curl: expose SOCKOPT/OPENSOCKET/CLOSESOCKET callbacks

- Thread: https://externals.io/message/131275
- Original archive: https://news-web.php.net/php.internals/131275
- Started by Xavier Leune on 2026-06-15T13:20:56+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #131275 — Xavier Leune — 2026-06-15T13:20:56+00:00

URL: https://externals.io/message/131275#131275

Hi internals,

PR #22159 adds three libcurl callback options to ext/curl for 8.6:

  - CURLOPT_SOCKOPTFUNCTION
  - CURLOPT_OPENSOCKETFUNCTION
  - CURLOPT_CLOSESOCKETFUNCTION

https://github.com/php/php-src/pull/22159

Motivation: give PHP users a native way to do SSRF filtering (validate the
resolved peer IP before connect) and low-level socket tuning
(SO_BINDTODEVICE, SO_MARK, keepalive, TCP_NODELAY...) without dropping to
ext/ffi.

Because the C signatures use a raw curl_socket_t fd, the callbacks bridge
to ext/sockets and exchange real Socket objects, fully usable with
 `socket_set_option()`, `socket_close()`, etc.

Thanks to @devnexen who helped me to improve the dependencies management
and the low level integration.
CI is fully green (Linux, macOS, FreeBSD, Windows, ASAN).

Feedback welcome on any matter.

Thanks,
Xavier Leune

---

## #131813 — Xavier Leune — 2026-07-08T12:03:38+00:00

URL: https://externals.io/message/131275#131813 · In reply to: #131275

Hi everyone,

Just want to add more context here: today PHP doesn't offer any good option
to prevent SSRF that points to localhost.
The options are tricky and error prone: that's exactly the use case of
the CURLOPT_OPENSOCKETFUNCTION callback, that was added to curl in 2007.
So, I'm not sure what the next step is, I remain available to iterate if
needed ; I would love to see this released before the feature freeze.

Have a nice day,

Xavier


Le lun. 15 juin 2026 à 15:20, Xavier Leune <xavier.leune+internals@gmail.com>
a écrit :

> Hi internals,
>
> PR #22159 adds three libcurl callback options to ext/curl for 8.6:
>
>   - CURLOPT_SOCKOPTFUNCTION
>   - CURLOPT_OPENSOCKETFUNCTION
>   - CURLOPT_CLOSESOCKETFUNCTION
>
> https://github.com/php/php-src/pull/22159
>
> Motivation: give PHP users a native way to do SSRF filtering (validate the
> resolved peer IP before connect) and low-level socket tuning
> (SO_BINDTODEVICE, SO_MARK, keepalive, TCP_NODELAY...) without dropping to
> ext/ffi.
>
> Because the C signatures use a raw curl_socket_t fd, the callbacks bridge
> to ext/sockets and exchange real Socket objects, fully usable with
> `socket_set_option()`, `socket_close()`, etc.
>
> Thanks to @devnexen who helped me to improve the dependencies management
> and the low level integration.
> CI is fully green (Linux, macOS, FreeBSD, Windows, ASAN).
>
> Feedback welcome on any matter.
>
> Thanks,
> Xavier Leune
