Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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
如何在php中通过系统命令替换exec()?_Php - Fatal编程技术网

如何在php中通过系统命令替换exec()?

如何在php中通过系统命令替换exec()?,php,Php,到目前为止,我的编码是: 如何在php中通过系统命令替换exec() if($str!="success") { $cmd = "rm -rf /portal/data/config/certificate/tmp/"; $error_text="Command : ".$cmd; AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH); $output = exec($cmd,$array1,$error_code)

到目前为止,我的编码是:

如何在php中通过系统命令替换
exec()

if($str!="success")
{
    $cmd = "rm -rf /portal/data/config/certificate/tmp/";
    $error_text="Command : ".$cmd;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $output = exec($cmd,$array1,$error_code);
    $error_text="Error code : ".$error_code;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    seterror('0:|:  :|: Could not apply certificate.');
    $error_text="Could not apply certificate";
    AddLog("sslconfig.php",$error_text,ERR_INFO);
    header("Location: ssl.php");
    exit;
}

if($certName==$cert_auth)
{
    //copy the applied certificate to fireballbundle.crt
    //$output = copysslfb("/portal/data/config/certificate/".$newfile.".crt");
    $error_text="Selfsigned Certicate";
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH); 
    $output="success";
} 
else 
{
    $error_text="Not Selfsigned Certicate";
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $output="success";
}

if($output!="success")
{
    $cmd = "rm -rf /portal/data/config/certificate/tmp/";
    $error_text="Command : ".$cmd;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $output = exec($cmd,$array1,$error_code);
    $error_text="Error code : ".$error_code;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $error_text="Could not add certificate to fireballbundle.crt : ".$output;
    AddLog("sslconfig.php",$error_text,ERR_ERROR);
    seterror('0:|: :|: Error in applying certificate.');
    header("Location: ssl.php");
    exit;
}
现在我想用系统命令替换exec命令

我在这里使用了三次
exec()
,如上面代码所示,现在我想用php中的
system()
命令替换

exec("hostname",$retval);
$output = exec($cmd,$array1,$error_code);
exec($cmd,$array1,$error_code);

要删除单个文件,应使用和删除应使用的目录。在这些页面上的注释中,您将发现许多不同的方法可以通过这些函数模拟
rm-rf

您应该尽可能避免使用
system
exec
。请经常查看php.net和google,看看您是否能够找到一种方法来使用内置函数或库执行任何操作。你不需要在这里使用这些设施

hostname
返回的内容您可能应该改为使用。

:)我在编码中也使用了unlink