PING的PHP exec()函数不适用于Cpanel

问题描述 投票:0回答:2

我创建了一个监视Network IPServer Status的应用程序。它适用于windows xampp server并且还在linux centos 6.0上进行了测试。两者都运作良好。但是,当我将脚本上传到安装了cpanel的网站时,我的脚本不在那里工作。那是一个linux托管服务器

我的Windows Ping命令:

$exec = exec( "ping www.google.com -n 3 ". $output, $status );

我对Centos的Ping命令:

$exec = exec( "ping www.google.com -c 3 ". $output, $status );

$output$status变量都返回准确值。但在cpanel中,$output为空,$status变量返回2而不是0或1

需要帮助谢谢,

php centos exec cpanel ping
2个回答
1
投票

检查您的主机提供商是否允许使用此功能,如果是,所以尝试使用这样的exec:

$exec = exec( "ping www.google.com -c 3 ", $output, $status );

如果它不工作你可以尝试另一个像exec的PHP函数:

system('ping www.google.com -c 3 ', $output);

你可以使用nagios来监控并在nagios上构建你的应用程序


0
投票
  1. 首先检查,您的托管服务提供商是否禁用了exec功能,使用给定的功能。此功能将列出您的托管服务提供商的所有已禁用功能。 function disabled_functions(){ $disabled = explode(',', ini_get('disable_functions')); return $disabled; } echo '<pre>'; print_r(disabled_functions());
  2. 如果exec存在于上述disabled_functions()的输出中,那么您必须咨询您的托管服务提供商以允许shell访问和执行。由于安全问题,托管服务提供商通常禁用shell访问和类似于exec的功能。
© www.soinside.com 2019 - 2024. All rights reserved.