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

时间:2014-10-25 03:09:08

标签: php centos exec cpanel ping

我创建了一个监控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

需要帮助 谢谢,

2 个答案:

答案 0 :(得分:1)

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

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

如果它不起作用,你可以尝试另一个像exec这样的php函数:

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

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

答案 1 :(得分:0)

  1. 请首先检查,您的托管服务提供商已禁用exec功能,或者不使用给定功能。此功能将列出您的托管服务提供商禁用的所有功能。

    function disabled_functions(){
      $disabled = explode(',', ini_get('disable_functions'));
      return $disabled;
    }
    echo '<pre>';
    print_r(disabled_functions());
    
  2. 如果上面的disable_functions()的输出中存在exec,那么您必须咨询托管服务提供商以允许shell访问和exec。 通常,由于安全问题,托管服务提供商会禁用外壳程序访问和类似于exec的功能。

相关问题