举个例子,如果启用了php exec,我会运行这个命令:/etc/init.d/mysql restart
或者我需要将!== false
设置为!== true
吗?
$var = exec('/etc/init.d/mysql restart');
if ($var !== false) {
echo "php exec is enabled";
}
基本上我要做的是,如果在服务器上启用此功能,则从php重启mysql
$var = exec('/etc/init.d/mysql restart');
if ($var !== false) {
exec('/etc/init.d/mysql restart');
echo "php exec is enabled and restart mysql";
}
答案 0 :(得分:2)
如何检查功能会给你带来错误
$var = exec(); // need to pass an argument
检查功能是否存在尝试
if(function_exists('exec')) {
echo "php exec is enabled";
}
另外根据更新,您需要将retrun参数传递给函数以检查返回值
exec('/etc/init.d/mysql restart', $output, $return);
// Return will return non-zero upon an error
if (!$return) {
echo "php exec is enabled";
}