php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66020 Can curl_getinfo() return IP address?
Submitted: 2013-11-02 12:44 UTC Modified: 2016-04-24 03:51 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: php dot bugs dot ws at jondh dot me dot uk Assigned: pierrick (profile)
Status: Closed Package: cURL related
PHP Version: Irrelevant OS: OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php dot bugs dot ws at jondh dot me dot uk
New email:
PHP Version: OS:

 

 [2013-11-02 12:44 UTC] php dot bugs dot ws at jondh dot me dot uk
Description:
------------
When using the cURL library, some domain names resolve to many IP addresses, but there's no way (as far as I can tell), in these cases, to see which IP was actually used. I think this would be useful.

I've discussed this with the author of Guzzle, and he seems to be in agreement that cURL presently offers no way to do this (see http://stackoverflow.com/a/19599373/472495).

Illustration script attached.

Test script:
---------------
<?php
$host = "www.google.com";

$ips = gethostbynamel($host);
if (count($ips) > 1) {
	echo sprintf("Host `%s` resolves to these IPs: %s\n", $host, implode(', ', $ips));
} else {
	die(sprintf("Host `%s` does not resolve to many IPs, so is not a good example\n", $host));
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$html = curl_exec($ch);
$ok = (bool) $html;
echo $ok ? "Call OK\n" : "Call failed\n";

// Show that there's no way to determine which IP was accessed
echo "Info:\n" . print_r(curl_getinfo($ch), true);

curl_close($ch);


Expected result:
----------------
This is a feature request, so if possible I'd like to see a new key returned by curl_getinfo, "ip_address", which would be populated with the address used by cURL for the connection. This would correspond to a new constant CURLINFO_IP_ADDRESS.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-11 04:28 UTC] francois dot bonzon at gmail dot com
This functionality already exists, but is currently not documented. I've sent today a patch to update the documentation, currently in review.

Use curl_getinfo($ch, CURLINFO_PRIMARY_IP) or look in the "primary_ip" key/value of curl_getinfo($ch).
 [2016-04-24 03:51 UTC] pierrick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pierrick
 [2016-04-24 03:51 UTC] pierrick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

CURLINFO_PRIMARY_IP is now in the documentation
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC