Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PING的PHP exec()函数不适用于Cpanel_Php_Centos_Exec_Cpanel_Ping - Fatal编程技术网

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

PING的PHP exec()函数不适用于Cpanel,php,centos,exec,cpanel,ping,Php,Centos,Exec,Cpanel,Ping,我创建了一个应用程序来监视网络IP或服务器状态。它在windowsxampp服务器上运行良好,并在linux centos 6.0上进行了测试。两者都很好。但是当我把脚本上传到一个安装了cpanel的网站时,我的脚本在那里不起作用。这是一个linux托管服务器 我的Windows Ping命令: $exec = exec( "ping www.google.com -n 3 ". $output, $status ); 我的Centos Ping命令: $exec = exec( "ping

我创建了一个应用程序来监视
网络IP
服务器状态
。它在windows
xampp服务器上运行良好
,并在
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

需要帮助吗
谢谢,

请检查您的主机提供商是否允许使用此功能。如果允许,请 试着像这样使用exec:

$exec=exec(“ping www.google.com-c3”,$output,$status)

如果它不起作用,您可以尝试另一个php函数,如exec:

system('ping www.google.com-c3',$output)

您可以使用nagios进行监视,并在nagios上构建应用程序

  • 首先检查,托管提供商是否已禁用exec函数,或者未使用给定函数禁用exec函数。此函数将列出托管提供商禁用的所有函数

    function disabled_functions(){
      $disabled = explode(',', ini_get('disable_functions'));
      return $disabled;
    }
    echo '<pre>';
    print_r(disabled_functions());
    
    功能禁用\u功能(){
    $disabled=explode(',',ini_get('disable_functions');
    返回$disabled;
    }
    回声';
    打印(禁用的函数());
    
  • 如果上述禁用的_functions()的输出中存在exec,则必须咨询宿主提供商以允许shell访问和exec。 由于安全问题,宿主提供程序通常会禁用shell访问和类似于exec的功能


  • 将句点更改为逗号(在命令和
    $output
    之间)。您没有收到错误,因为它是一个串联运算符(从技术上讲,这在语法上是正确的),但它也没有用数据填充变量……我尝试将句点更改为逗号,但结果是,提供cpanel类型服务的主机提供商不允许使用
    exec()
    ;您可以验证情况并非如此。