【发布时间】:2021-06-06 10:14:01
【问题描述】:
当我尝试将 url 传递给 file_get_contents 时,我得到了这个
警告: file_get_contents(http://localhost:8001/els/get_data_from_radius.php?id=1&u=GERONIMO-ANGELA-GLADIS-17010-16407&p=5T7U5756876O93FPG7F2B56B89359488&s=1&action=2&ud=524288/5242880): 无法打开流:无法分配请求的地址 /var/local/entropia/model/MonitoreoRadiusWrapper.php上线 108
我的功能是
public static function activar_servicio($ws_host, $id_rad, $user, $pass, $simultaneo, $ud_mikrotik) {
$url = $ws_host . ":8001/els/get_data_from_radius.php?id=$id_rad&u=$user&p=$pass&s=$simultaneo&action=2&ud=$ud_mikrotik";
$result = file_get_contents($url);
return json_decode($result);
}
我在带有 nginx 的 docker 容器中使用 php 7。
【问题讨论】:
-
如果这是使用任何类型的代理,您可能需要通过传递给 file_get_contents 的流上下文指定,请参阅stackoverflow.com/a/53185479/1427878
-
8001是内部还是外部暴露的 Docker 端口?此外,您的代码是否有理由对其自身进行 API 调用?您是否可以只使用实际逻辑而无需额外的 HTTP 请求? -
8001 是外部端口。我真的不知道这是否有原因。我是这个项目的新手。