一起看看PHP施行普通shell下令流程
【相关学习引荐:php图文教程】
这里演示一些一般的shell命令
php施行shell命令,可以使用下面几个函数:
string system ( string $command [, int &$return_var ] )
string exec ( string $command [, array &$output [, int &$return_var ]] )
void passthru ( string $command [, int &$return_var ] )
留意的是:这三个函数在默许的状况下,都是被制止了的,假如要使用这几个函数,就要先修改php的配置文件php.ini,查寻关键字disable_functions,将这一项中的这几个函数名删除掉,然后留意重新启动apache。
第一看一下system()和passthru()两个功效相似,可以互换:
<?php $shell = "ls -la"; echo "<pre>"; system($shell, $status); echo "</pre>"; //留意shell命令的施行结果和施行返回的状态值的对应关系 $shell = "<font color='red'>$shell</font>"; if( $status ){ echo "shell命令{$shell}施行失败"; } else { echo "shell命令{$shell}成功施行"; } ?>
施行结果如下:
留意,system()会将shell命令施行之后,立马显示结果,这一点会比力不利便,由于我们有时候不需要结果立马输出,乃至不需要输出,于是可以用到exec()
exec()的使用示例:
<?php $shell = "ls -la"; exec($shell, $result, $status); $shell = "<font color='red'>$shell</font>"; echo "<pre>"; if( $status ){ echo "shell命令{$shell}施行失败"; } else { echo "shell命令{$shell}成功施行, 结果如下<hr>"; print_r( $result ); } echo "</pre>"; ?>
运转结果如下:
相关学习引荐:php编程(视频)
以上就是一起看看PHP施行一般shell命令流程的具体内容,更多请关注百分百源码网其它相关文章!