Skip to content

Expose in-flight Request via optional 'request' option callback#45

Open
owner888 wants to merge 2 commits into
workerman-php:masterfrom
owner888:expose-request-handle
Open

Expose in-flight Request via optional 'request' option callback#45
owner888 wants to merge 2 commits into
workerman-php:masterfrom
owner888:expose-request-handle

Conversation

@owner888

@owner888 owner888 commented Jul 3, 2026

Copy link
Copy Markdown

What

Expose the in-flight Request object to callers via an optional 'request' option callback:

$http->request($url, [
    'method' => 'POST',
    'request' => function ($request) use (&$handle) { $handle = $request; },
    // ...
]);
// later, e.g. when the downstream client disconnects:
$handle->getConnection()->close();

Why

There is currently no way to cancel an in-flight request. For long-running streaming
responses (e.g. LLM SSE streaming via webman/openai), when the downstream client
disconnects, the upstream request keeps running to completion — wasting resources
(and paid LLM tokens).

With the Request handle exposed, callers can close the underlying connection to abort.

Notes

  • Fully backward compatible: nothing changes unless the 'request' option is set.
  • When a redirect is followed, the callback fires again with the new Request,
    so the caller always holds the live handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant