简体   繁体   English

如何限制php exec()只执行R脚本?

[英]How to restrict php exec() only execute R script?

I use PHP exec() to execute an R script like this: 我使用PHP exec()执行R脚本,如下所示:

exec("Rscript foo.R", $return);

But I've heard that it's very dangerous to use exec on the server. 但是我听说在服务器上使用exec非常危险。 How can I restrict exec to execute only R scripts? 如何限制exec只执行R脚本?

Indeed, it's kind of dangerous. 确实,这很危险。 I wouldn't use exec for that, to be honest. 老实说,我不会使用exec。 But if you really want to use it, just check if R file exists before forwarding it's name to exec. 但是,如果您真的要使用它,只需在将其名称转发给exec之前检查R文件是否存在。 Of course, you should also ensure that the file has only R extension and the name doesn't contain relative path. 当然,您还应该确保该文件仅具有R扩展名,并且名称不包含相对路径。

You can use exec 您可以使用exec

exec is used to run process in background... exec用于在后台运行进程...

We use this 我们用这个

for eg: my report take at least 20-30 min, as it have many join and trillion of record. 例如:我的报告至少要花20到30分钟,因为它有许多联接并且有上万亿记录。 So, what we did is we use exec to run our script in background and pop message "We will send you an email with in 30min, no need to wait you can do other stuff... etc., 因此,我们要做的是使用exec在后台运行脚本并弹出消息“我们将在30分钟内向您发送一封电子邮件,无需等待您可以执行其他操作……等等,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM