使用PHP shell_exec()循环:使用php()或bash for-do-done? [英] Loops with PHP shell_exec() : Use php for() or bash for-do-done?

查看:170
本文介绍了使用PHP shell_exec()循环:使用php()或bash for-do-done?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想用PHP shell_exec()执行命令 mycommand > 10次。我应该做一个bash循环:

  shell_exec('for i in {1..10} do mycommand -i done') ; 

或者是一个PHP循环:

<$ p ($ i = 1; $ i< = 10; ++ $ i){shell_exec('mycommand - '。$ i); $ p> }

什么原因(安全,性能,样式等)其他?

解决方案

转到bash循环,因为 shell_exec 只有一次。这比多次调用 shell_exec 要快。启用像exec这样的函数,shell_exec本身就是一个很大的安全问题。如果有人设法在您的服务器上传一个PHP shell,那么他可以破解您的服务器。


Let's say I want to execute the command mycommand with PHP shell_exec() 10 times. Should I do a bash loop:

shell_exec('for i in {1 .. 10} do mycommand -i done');

or rather a PHP loop:

for($i = 1; $i <=10; ++$i) { shell_exec('mycommand -'.$i); }

What are the reasons (security, performance, style, ...) to choose one over the other?

解决方案

Go for bash loop, because shell_exec function is called only once. It will be faster than calling shell_exec multiple times. Enabling functions like exec, shell_exec itself a big security issue. If someone managed to upload a PHP shell in your server then he can hack your server.

这篇关于使用PHP shell_exec()循环:使用php()或bash for-do-done?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆