如何在php中通过系统命令替换exec()?
到目前为止,我的编码是: 如何在php中通过系统命令替换如何在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)
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