php fopen 无法在我的服务器上运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9038694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:01:08  来源:igfitidea点击:

fopen is not working on my server

php

提问by Fischer

It works perfectly on localhost with Xampp, but when I try it on my server (host-ed.net), fopen can't open any url, it only works for files without http.

它在本地主机上与 Xampp 完美配合,但是当我在我的服务器(host-ed.net)上尝试它时,fopen 无法打开任何 url,它仅适用于没有 http 的文件。

<?php
$file="http://www.google.es";
$gestor = fopen($file, "r") or die ("Nothing");
?>

In my server with this code shows Nothing. Can be anything on the php.ini ?

在我的带有此代码的服务器中,什么也没有显示。php.ini 上可以有任何内容吗?

EDIT: In the php.ini: allow_url_fopen = On

编辑:在 php.ini 中:allow_url_fopen = On

EDIT: It's solved. My server had it disabled, but now it's enabled. Thanks for the answers.

编辑:它已经解决了。我的服务器禁用了它,但现在启用了。感谢您的回答。

回答by Charles

fopen can't open any url

fopen 无法打开任何网址

Check the value of the allow_url_fopenphp.ini setting:

检查allow_url_fopenphp.ini 设置的值:

var_dump(ini_get('allow_url_fopen'));

It's probably false. You'll need to speak to your web host, or try another method. Mabye CURLis enabled?

很可能是假的。您需要与您的网络托管服务商联系,或尝试其他方法。Mabye CURL已启用?

You should also check your error_reportingand display_errorsvalues. PHP should have complained loudly about being unable to open the URL. You'll want to turn both of them all the way up while developing code, so you can understand what goes wrong easier.

您还应该检查您的error_reportingdisplay_errors值。PHP 应该大声抱怨无法打开 URL。在开发代码时,您会希望将它们全部调高,这样您就可以更容易地了解出了什么问题。

回答by lorenzo-s

回答by Asaph

The permission for opening urls with fopenis controlled by the php.inisetting allow_url_fopen. You can see your current setting using phpinfo()which will dump an html doc containing all your server settings.

打开 url 的权限fopenphp.ini设置控制allow_url_fopen。您可以使用phpinfo()它将转储包含所有服务器设置的 html 文档来查看当前设置。

回答by Dave

As http://php.net/manual/en/function.fopen.phpstates,

正如http://php.net/manual/en/function.fopen.php所述,

If filename is of the form "scheme://...", it is assumed to be a URL and PHP will search for a protocol handler (also known as a wrapper) for that scheme. If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename specifies a regular file.

如果文件名的格式为“scheme://...”,则假定它是一个 URL,PHP 将搜索该方案的协议处理程序(也称为包装器)。如果没有注册该协议的包装器,PHP 将发出通知以帮助您跟踪脚本中的潜在问题,然后继续像 filename 指定一个常规文件一样。

I would therefore assume that there is no registered wrapped for url's, and php is treating that as a regular filename, which doesn't exist.

因此,我假设 url 没有注册包装,并且 php 将其视为不存在的常规文件名。

回答by Cheery

Do you have a free hosting account? Most hosting services limit outgoing connection for free accounts to prevent abuse. Try this:

你有免费的主机账户吗?大多数托管服务限制免费帐户的传出连接以防止滥用。尝试这个:

$fp = fsockopen("some.alive.site", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    echo "Everything is OK";
    fclose($fp);
}

If you'll see an error message - you are not allowed to make outgoing connections.

如果您会看到一条错误消息 - 您不能进行传出连接。

回答by marcovtwout

If you are using PHP-FPM, also check the configuration files in pool.d/. PHP-FPM pools can override php settings by using php_admin_flag, php_admin_value, php_flagor php_value. (We encountered this on a Ubuntu 16 vps)

如果您使用的是 PHP-FPM,还要检查pool.d/. PHP-FPM池可以使用覆盖PHP的设置php_admin_flagphp_admin_valuephp_flagphp_value。(我们在 Ubuntu 16 vps 上遇到过这个问题)