php详细命令,PHP调用linux命令详细说明:

PHP调用linux命令详细说明

在php教程中调用linux命令的函数是

string exec(string command, string [array], int [return_var]);

如:

exec( "vpopmail ");

echo exec('whoami');

再看一实例①

function exec_enabled() {

$disabled = explode(', ', ini_get('disable_functions'));

return !in_array('exec', $disabled);

}

$tmp = exec("c:\Image\gm.exe convert c:\Image\file1.tiff c:\Image\file1.jpg", $results);

?>

还有一种命令是

php通过函数system()调用系统命令。

string system ( string $command [, int &$return_var ] )

实例②

system('asterisk -vvvvvvvvvvvc');

system()是一样的函数C的,它执行给定的命令和输出结果的版本。该system()的调用也尝试自动刷新网页服务器的输出缓冲器在每个输出行如果PHP运行作为服务器模块。如果你需要执行一个命令,并已全部通过直接从背面没有任何干扰的命令数据,使用passthru()函数。

$last_line = system('ls', $retval);

function my_exec($cmd, $input='')

{$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes);

fwrite($pipes[0], $input);fclose($pipes[0]);

$stdout=stream_get_contents($pipes[1]);fclose($pipes[1]);

$stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);

$rtn=proc_close($proc);

return array('stdout'=>$stdout,

'stderr'=>$stderr,

'return'=>$rtn

);

}

var_export(my_exec('echo -e $(

实例三

$cmd = "date";

$output = system($cmd);

printf("System Output: $outputn");

exec($cmd, $results);

printf("Exec Output: {$results[0]}n");

php调用linux命令的权限问题

你可以使用定时任务执行你要调用的php,这时的权限就是root,

php通过函数system()调用系统命令

php一般是以apache用户身份去执行的,把apache加入到存储你文件的父文件夹属组里去,然后改该父文件夹权限为775,这样属组成员就有写的权限,而apache属于这个组就可以改写该目录下所有文件的权限,当然,属组最好不要是root,你可以为该文件夹改个其它普通用户组。

改apache/php的运行用户方法不安全

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值