作为一个有点丑陋的黑客让它工作,你可以添加一个hosts文件别名,或许用一个小时cronjob加强来更新真正的IP--代价是脚本每次实际上只有1个小时改变IP? (我实际上做了几年,当我面临类似的问题时,我不认为我仍然有源代码,虽然,检查)
编辑:我没有原始的cronjob,但它看起来是这样的:
<?php
declare(strict_types = 1);
$hosts = '/etc/hosts';
assert (is_file ($hosts) && is_readable ($hosts) && is_writable ($hosts), 'need access to ' . $hosts);
$host = 'google.com';
$ip = getIP ($host);
$str = file_get_contents ($hosts);
$start = strpos ($str, '#<wtf_cronjob>');
$end = strpos ($str, '#</wtf_cronjob>');
assert (false !== $start && false !== $end, 'invalid syntax for hosts file!');
$end += strlen ('#</wtf_cronjob>');
$newstr = substr ($str, 0, $start) . '#<wtf_cronjob>' . "\n" . $ip . ' ' . $host . ' ' . "\n" . '#</wtf_cronjob>' . substr ($str, $end);
file_put_contents ($hosts, $newstr);
function getIP(string $host, string $dns = '8.8.8.8'): string {
exec ('host ' . escapeshellarg ($host) . ' ' . escapeshellarg ($dns) . ' 2>&1', $lines, $ret);
if ($ret !== 0) {
ob_start();
var_dump ($lines, $ret);
$debugstr = ob_get_clean();
throw new \RuntimeException ('host failed. debuginfo: ' . $debugstr);
}
foreach ($lines as $line) {
if (false === stripos ($line, 'has address ')) {
continue;
}
// found it
$ret = trim (substr ($line, stripos ($line, 'has address ') + strlen ('has address ')));
if (! filter_var ($ret, FILTER_VALIDATE_IP)) {
throw new \RuntimeException ('the extracted ip address is invalid! (wrong syntax for host?)');
}
return $ret;
}
throw new \RuntimeException ('could not find ip address!');
}
在hosts文件以下新行:
#<wtf_cronjob>
216.58.209.142 google.com
#</wtf_cronjob>
嗨,不幸的是,我们没有代理,它不能解释为什么它是网络特定的问题。相同的设备,相同的配置,相同的请求,通过一个AP,它不能工作,通过另一个AP工作。 –
也许你的接入点是这个问题?访问有一些防火墙配置?你是否尝试使用@hanshenrik说的尝试?测试是一个好主意。 –
问题不是关于一个AP。它发生在服务器和我的本地机器上。我试图手动分配域应该如何解决。在我的例子中,有一个错误 - 应该是端口443,而不是80(但是关于未知主机名的消息很奇怪)。由于这个尝试,请求正在工作,删除后,它仍然有效。 –