【相干学习保举:php图文教程】
这里演示一些一般的shell饬令
php执行shell饬令,能够应用上面几个函数:
string system ( string $co妹妹and [, int &$return_var ] )
string exec ( string $co妹妹and [, array &$output [, int &$return_var ]] )
void passthru ( string $co妹妹and [, 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饬令流程的具体内容,更多请存眷资源魔其它相干文章!
标签: php php开发教程 php开发资料 php开发自学 执行 shell命令
抱歉,评论功能暂时关闭!