在将我的网站移动到新域后,我遇到了一些奇怪的问题,即file_get_contents.我不得不设置一个新域和IP地址(使用Plesk)来获得新的ssl证书.现在我的file_get_contents在同一个域上调用脚本给了我这个:
无法打开流:HTTP请求失败!找不到HTTP/1.1 404
如果我在另一台服务器上使用file_get_contents调用相同的url它工作正常,如果我从服务器调用www.google.com失败,那么它似乎只是在同一个服务器上调用url!
我觉得它可能与在一台服务器上拥有两个不同的ssl证书的两个IP有关,当我从服务器获取服务器的file_get_contents /(索引页面)时我得到了plesk'这是一个新的域'页面所以当它从自己的服务器调用时,它就像查找正确的虚拟主机一样.
澄清(希望!):
在托管域的服务器上:
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
Run Code Online (Sandbox Code Playgroud)
给出"无法打开流:HTTP请求失败!找不到HTTP/1.1 404"
file_get_contents('http://www.google.com');
Run Code Online (Sandbox Code Playgroud)
工作正常
在另一台服务器上
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
Run Code Online (Sandbox Code Playgroud)
工作良好.
我试过关闭ssl,我仍然遇到同样的问题.
我正试图在xampp服务器上的网站上使用php脚本从服务器下载图像.
正在使用函数file_get_contents下载映像.
在服务器上下载的php代码是:
if(isset($_GET['path']) && isset($_GET['username'])) {
echo "path:".$_GET['path'];
$temp = explode(".", $_GET['path']);
$extension = end($temp);
$fname="images/".$_GET['title'];
$filenameIn = $_GET['path'];
$filenameOut = "" . $fname;
$contentOrFalseOnFailure = file_get_contents($filenameIn);
$byteCountOrFalseOnFailure = file_put_contents($filenameOut,$contentOrFalseOnFailure);
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
警告:file_get_contents():php_network_getaddresses:getaddrinfo failed:第19行的/opt/lampp/htdocs/xampp/project/upload_art.php中未知的名称或服务
警告:file_get_contents(http://app6.pixlr.com/_temp/528afa6e2f7cc6a5b1000101.jpg):无法打开流:php_network_getaddresses:getaddrinfo failed:/ opt/lampp/htdocs/xampp/project/upload_art中未知名称或服务.第19行的PHP
我已经检查了所有发布的答案,但似乎没有解决问题.请帮忙!
此代码不适用于服务器.但它正在我的localhost(xampp)工作
$url = file_get_contents('http://www.site.com/');
$xhtml='|<tr style="background-color:#dddddd;">
<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>
</tr>|i';
preg_match_all($xhtml,$url,$score);
array_shift($score);
echo"<pre>";
print_r($score);
echo"</pre>";
Run Code Online (Sandbox Code Playgroud)
当我像这样更改代码时,它会打印另一个分数.因为这样有两行.它有相同的代码.顺便说一句下面的代码工作到服务器.
$xhtml='|<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>|i';
Run Code Online (Sandbox Code Playgroud)
我需要在代码之间取两个值.
allow_url_fopen = on
Run Code Online (Sandbox Code Playgroud) 我需要获取图像的MIME类型,但我只有我所拥有的图像的主体file_get_contents.是否有可能获得MIME类型?
我正在尝试使用file_get_contents()来从服务器获取响应并遇到此错误.有人能告诉我是什么原因以及如何解决它?代码的一部分是:
$api = "http://smpp5.routesms.com:8080/bulksms/sendsms?username=$username&password=$password&source=$source&destination=$destin&dlr=$dlr&type=$type&message=$message";
$resp = file_get_contents($api);
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中粘贴网址时,服务器响应正确.我了解到这是由服务器拒绝客户端的HTTP版本引起的,但我不知道为什么会发生这种情况.
任何帮助深表感谢.提前致谢
$url = 'http://a.url/i-know-is-down';
//ini_set('default_socket_timeout', 5);
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 5,
'ignore_errors' => true
)
)
);
$start = microtime(true);
$content = @file_get_contents($url, false, $ctx);
$end = microtime(true);
echo $end - $start, "\n";
Run Code Online (Sandbox Code Playgroud)
我得到的反应一般是21.232 segs,不应该是大约5秒???
取消注释ini_set行根本没有帮助.
下面的代码是查询我正在建立的大学项目的搜索引擎的在线词库,但我遇到了file_get_contents "未能打开流"错误的问题.当我发送词库时,词库无法识别,它会引发错误.我正在尝试编写一段代码来忽略错误,只是在没有信息的情况下继续进行.
$thesaurus_search="http://words.bighugelabs.com/api/2/0089388bb57f/".$this->formatted_query."/php";
$result_thesaurus=file_get_contents($thesaurus_search);
Run Code Online (Sandbox Code Playgroud)
我试过了:
if (file_get_contents($thesaurus_search) != NULL)
{ // do stuff }
Run Code Online (Sandbox Code Playgroud)
...但它不起作用,因为它仍然返回某种字符串.
我该怎么处理这种情况?
我已经搜索了此错误的问题,但我对我自己的许多已开始显示此错误的服务器之间可能发生的情况感到困惑:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /var/www/html/file_get.php on line 7
Run Code Online (Sandbox Code Playgroud)
第 7 行是 file_get_contents 命令。
这些是我控制下的(Debian)服务器,所以我知道(据我所知)没有发生/更改或更新/升级。
我知道我可以使用包含以下内容的解决方案,但我很想了解首先发生了什么(加上我有很多很多文件需要更新)。我还真的需要了解哪台服务器存在潜在问题。
我有 3 台服务器,所有这些服务器都通过 file_get_contents 请求访问另一台第四台服务器。其中 2 个服务器突然(今天几个小时前)开始出现上述错误,第三个服务器似乎仍然工作正常。
我怀疑问题出在显示问题的两台服务器上,而不是它们都试图访问的第四台服务器上。
如果我实现这段代码,它会起作用,但我宁愿找到根本原因:
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
Run Code Online (Sandbox Code Playgroud)
并将 file_get_contents 修改为以下内容:
file_get_contents($input, false, stream_context_create($arrContextOptions)));
Run Code Online (Sandbox Code Playgroud)
但正如前面提到的,我有数百个文件需要更改。
所有服务器都是 Debian 并使用 Lets Encrypt 证书 9(这是有效的)。
我尝试将以下内容添加到 php.ini:
openssl.cafile=/etc/letsencrypt/live/myserver.com/cert.pem
Run Code Online (Sandbox Code Playgroud)
但这并没有奏效(同样的错误仍然存在)。
仍然有效的服务器的 openssl 版本是 OpenSSL 1.1.0f 25 May 2017 (库:OpenSSL 1.1.0l 10 Sep 2019),显示错误的两个是 OpenSSL 1.1.0l 10 Sep 2019 不确定这是否相关。 …
目前我正在使用file_get_contents()将GET数据提交到一个站点数组,但是在执行页面时我收到此错误:
致命错误:超出最长执行时间30秒
我真正希望脚本做的就是开始加载网页,然后离开.每个网页最多可能需要5分钟才能完全加载,我不需要它完全加载.
这是我目前拥有的:
foreach($sites as $s) //Create one line to read from a wide array
{
file_get_contents($s['url']); // Send to the shells
}
Run Code Online (Sandbox Code Playgroud)
编辑:为了清除任何混淆,此脚本用于在其他服务器上启动脚本,不返回任何数据.
编辑:我现在正试图使用cURL来做这个技巧,通过设置一秒的超时使其发送数据然后停止.这是我的代码:
$ch = curl_init($s['url']); //load the urls
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); //Only send the data, don't wait.
curl_exec($ch); //Execute
curl_close($ch); //Close it off.
Run Code Online (Sandbox Code Playgroud)
也许我把选项设置错了.在我们发言时,我正在查看一些手册.只是给你一个更新.谢谢你们所有帮助我的人.
编辑:啊,发现了问题.我使用的是CURLOPT_CONNECTTIMEOUT而不是CURLOPT_TIMEOUT.哎呦.
但是现在,脚本没有触发.它们每个都使用ignore_user_abort(TRUE); 所以我无法理解这个问题
哈,划伤那个.现在工作.非常感谢大家
我试图将这里显示的表解析成一个多维的PHP数组.我使用以下代码但由于某种原因它返回一个空数组.在网上搜索后,我发现这个网站是我从中获得parseTable()函数的地方.通过阅读该网站上的评论,我发现该功能完美无缺.所以我假设我从file_get_contents()获取HTML代码的方式有问题.对我做错了什么的想法?
<?php
$data = file_get_contents('http://flow935.com/playlist/flowhis.HTM');
function parseTable($html)
{
// Find the table
preg_match("/<table.*?>.*?<\/[\s]*table>/s", $html, $table_html);
// Get title for each row
preg_match_all("/<th.*?>(.*?)<\/[\s]*th>/", $table_html[0], $matches);
$row_headers = $matches[1];
// Iterate each row
preg_match_all("/<tr.*?>(.*?)<\/[\s]*tr>/s", $table_html[0], $matches);
$table = array();
foreach($matches[1] as $row_html)
{
preg_match_all("/<td.*?>(.*?)<\/[\s]*td>/", $row_html, $td_matches);
$row = array();
for($i=0; $i<count($td_matches[1]); $i++)
{
$td = strip_tags(html_entity_decode($td_matches[1][$i]));
$row[$row_headers[$i]] = $td;
}
if(count($row) > 0)
$table[] = $row;
}
return $table;
}
$output = parseTable($data);
print_r($output);
?>
Run Code Online (Sandbox Code Playgroud)
我希望我的输出数组看起来像这样:
1 -- …
php ×10
curl ×2
http ×2
api ×1
content-type ×1
curl-multi ×1
html-parsing ×1
mime-types ×1
openssl ×1
plugins ×1
regex ×1