首页 > 解决方案 > PHP - File_get_contents 在远程服务器上不起作用

问题描述

file_get_content 在运行 php 5.6 的远程服务器上不起作用。

我做了一个测试脚本,只是调用 file_get_contents(' https://google.com ') 它给了我以下错误:

Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to 
allocate 319144 bytes) in FILE_PATH on line 14

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('memory_limit', '1024m');

//$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
//$context = stream_context_create($opts);
echo "<pre>";
print_r(file_get_contents("https://google.com"));
echo "</pre>";
echo "test";

//$w = stream_get_wrappers();
//echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
//echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
//echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
//echo 'wrappers: ', var_export($w);

 ?>

我用谷歌搜索过,大多数解决方案都改变了

allow_url_fopen 为 1/on 或增加内存限制,我都做了无济于事。

此外,如果我添加标题它可以工作,但它以前不需要它。

任何帮助都会非常感激。

此外,它的运行:nginx/1.6.2 Apache/2.2.22

标签: phpapachenginxremote-server

解决方案


推荐阅读