php 通过 CLI 获取“不推荐使用以‘#’开头的评论”消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14074101/
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-25 06:34:36  来源:igfitidea点击:

Getting "Comments starting with '#' are deprecated" message via CLI

php

提问by aravind.udayashankara

I have a very limited access to server php configuration files .

我对服务器 php 配置文件的访问非常有限。

when I run some of my cron scripts which involves writing log files , I am getting a warning like this

当我运行一些涉及写入日志文件的 cron 脚本时,我收到了这样的警告

Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0

I googled a lot to find the reason , I got to know that we need to replace the '#' with ';' in ming.ini file .

我在谷歌上搜索了很多以找到原因,我知道我们需要用 ';' 替换 '#' 在 ming.ini 文件中。

I informed this to my server admin to fix this

我将此通知我的服务器管理员以解决此问题

below is the link where I got this fix

下面是我得到这个修复的链接

How to fix: PHP Deprecated errors

如何修复:PHP 弃用错误

Later , for some of the scripts issue got fixed but for some of them I started getting same error in different php configuration file

后来,对于一些脚本问题得到了修复,但对于其中一些我开始在不同的 php 配置文件中遇到相同的错误

eg .

例如。

PHP Deprecated:  Comments starting with ‘#' are deprecated in /etc/php5/cli/conf.d/imagick.ini on line 1 in Unknown on line 0

PHP Deprecated:  Comments starting with ‘#' are deprecated in /etc/php5/cli/conf.d/imap.ini on line 1 in Unknown on line 0

What actually is the problem , below is my server specification

究竟是什么问题,下面是我的服务器规格

OS : ubuntu 12 php : 5.4

操作系统:ubuntu 12 php:5.4

Is this a usual behaviour do I need to change these comments from '#' to ';' in every file .

这是一种常见的行为,我是否需要将这些注释从“#”更改为“;” 在每个文件中。

OR is this an issue with PHP 5.4 .

或者这是 PHP 5.4 的问题。

Please provide any information if you have or an easy way to avoid this error in application level ( code )

如果您有任何信息或在应用程序级别(代码)避免此错误的简单方法,请提供任何信息

Thanks in advance for reading this post

提前感谢您阅读这篇文章

回答by Gumbo

You can patch the comments with this shell command:

您可以使用此 shell 命令修补注释:

find /etc/php5/cli/conf.d/ -name "*.ini" -exec sed -i -re 's/^(\s*)#(.*)/;/g' {} \;

It basically finds all .inifiles below /etc/php5/cli/conf.d/and executes sedon it, which replaces any #comment line literal by ;.

它基本上找到/etc/php5/cli/conf.d/ 下的所有.ini文件并在其上执行sed,它将任何注释行文字替换为.#;

回答by AMB

you need to find lines starting with '#' in your php.ini file and change it to ';'

您需要在 php.ini 文件中找到以“#”开头的行并将其更改为“;”

回答by Deepak Chawla

It shows that in your php.ini file have some error.To resolve it you can load default php.ini file by using below command.

它表明您的 php.ini 文件中有一些错误。要解决它,您可以使用以下命令加载默认的 php.ini 文件。

It will rename your pervious php.ini file to php.ini_old.

它会将您之前的 php.ini 文件重命名为 php.ini_old。

sudo mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini_old

than it will copy default php.ini file to /etc/php5/apache2/ location.

它将默认的 php.ini 文件复制到 /etc/php5/apache2/ 位置。

sudo cp /usr/share/php5/php.ini-production /etc/php5/apache2/php.ini

Hope it works.

希望它有效。

回答by Svetoslav Marinov

In my case I had to parse mysql.ini and php.ini files. You don't control how the comments are used in those files so I suppressed the warnings just for that line.

就我而言,我必须解析 mysql.ini 和 php.ini 文件。您无法控制这些文件中注释的使用方式,因此我仅针对该行取消了警告。

$parse_sections = true;
$cfg = @parse_ini_file($file, $parse_sections);

I am sure there's a way would be to read the file line by line, replace the '#" comments and then use parse_ini_string() to parse the whole thing but this adds a little bit of overhead.

我确信有一种方法是逐行读取文件,替换“#”注释,然后使用 parse_ini_string() 来解析整个内容,但这会增加一点开销。

回答by fbitterlich

You could try to set the PHP error_reporting configuration, like this:

您可以尝试设置 PHP error_reporting 配置,如下所示:

ini_set("error_reporting", E_ALL & ~E_DEPRECATED);

However, this is only a temporary fix. Getting a warning like this means that with some later version of PHP, it won't work any more at all, as the configuration files will be treated as invalid. Better cntact your hoster and ask them to fix it; shouldn't be too difficult.

但是,这只是临时修复。收到这样的警告意味着在某些更高版本的 PHP 中,它根本不再起作用,因为配置文件将被视为无效。最好联系您的主机并要求他们修复它;应该不会太难。