“Get the proxy” can mean three different things in a PHP cURL application. Decide which observation you need before adding another request.

QuestionWhere to look
What endpoint did the application configure?The configuration supplied to the handle
Was a proxy used for this transfer?Transfer information, where supported
What public address did the website see?An observation at that destination

Keep the selected endpoint alongside the handle or request object. curl_getinfo is a transfer-information interface, not a general getter for every CURLOPT value previously assigned. Retaining the application configuration is simpler than trying to intercept curl_setopt calls.

Inspect the completed transfer

After the transfer, the connected peer is available through CURLINFO_PRIMARY_IP. When the first connection goes to a proxy, that peer can be the proxy's address rather than the website's address.

$peer = curl_getinfo($ch, CURLINFO_PRIMARY_IP);
$usedProxy = defined('CURLINFO_USED_PROXY')
    ? curl_getinfo($ch, constant('CURLINFO_USED_PROXY'))
    : null;

CURLINFO_USED_PROXY was added to libcurl in 8.7.0 and is exposed by compatible PHP builds. Its result reports proxy use, not the selected proxy's complete URL. If the constant is unavailable, null above means the observation is unavailable, not that the request went directly.

Read these values while the handle still describes the operation in question. A failed connection may not yield a useful peer address, and an explicit proxy can still be bypassed by an applicable exclusion.

An IP-check endpoint answers the third question. Its reply can describe an exit behind the proxy, while the configured hostname resolves to a different entrance. Neither address should be substituted for the other in the application's settings.

Tënë sô zo