如何在 PHP/cURL 中使用不同的服务器 IP?

发布于 2024-09-19 13:20:19 字数 44 浏览 3 评论 0原文

我有一台分配了不同 IP 的服务器,如何指定 cURL 使用不同的 IP?

I have a server with different IPs assigned, how can I specifiy a different IP to be used by cURL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自由范儿 2024-09-26 13:20:19

您必须使用 CURLOPT_INTERFACE 选项:

传出网络的名称
接口来使用。这可以是一个
接口名称、IP 地址或
主机名。

它可以按以下方式使用:

curl_setopt($ch, CURLOPT_INTERFACE, "XXX.XXX.XXX.XXX");

当然,这仅接受来自本地计算机的 IP 和主机名。

You will have to use the CURLOPT_INTERFACE option:

The name of the outgoing network
interface to use. This can be an
interface name, an IP address or a
host name.

It can be used in the following manner:

curl_setopt($ch, CURLOPT_INTERFACE, "XXX.XXX.XXX.XXX");

This ofcourse, only accepts IPs and hostnames from your local machine.

迷鸟归林 2024-09-26 13:20:19

此处快速提示

$tuCurl = curl_init(); 
curl_setopt($tuCurl, CURLOPT_URL, "http://ip/path");
//curl_setopt($tuCurl, CURLOPT_URL, "http://domain");

ubuntu 中的示例

更改 /etc/apache2/sites-available/default

curl_setopt($tuCurl, CURLOPT_URL, "http://project1.local");
curl_setopt($tuCurl, CURLOPT_URL, "http://127.0.0.1/project1");

Here quick tip

$tuCurl = curl_init(); 
curl_setopt($tuCurl, CURLOPT_URL, "http://ip/path");
//curl_setopt($tuCurl, CURLOPT_URL, "http://domain");

example in ubuntu

change /etc/apache2/sites-available/default

curl_setopt($tuCurl, CURLOPT_URL, "http://project1.local");
curl_setopt($tuCurl, CURLOPT_URL, "http://127.0.0.1/project1");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文