简体   繁体   English

运行php exec()进行后台进程

[英]Running php exec() for background process

I have set up a line of code in my class to run a function in the background using the following line on my linux server: 我在我的类中设置了一行代码,以便在Linux服务器上使用以下代码行在后台运行函数:

$cmd = "nohup wget -q <-url here-> /dev/null 2>&1 &")"; $exec = exec( 'bash -c "'.$cmd.'"' );

(with the url just pointing to my script) (网址仅指向我的脚本)

This is working fine and doing what I want it do, however everytime this runs it is creating a new file in my root (public_html) and they are all numbered like 10, 10.1, 10.2, 10.3 etc. 这可以正常工作,并且可以执行我想要的操作,但是每次运行时,它都会在我的根目录(public_html)中创建一个新文件,它们的编号都分别为10、10.1、10.2、10.3等。

Does anybody know how I can stop these being created? 有人知道我该如何阻止这些创作?

Also if this is bad practice and anybody wants to suggest a better way of doing something like this, any advice is greatly appreciated. 同样,如果这是不好的做法,并且任何人都想提出一种更好的方法来做这样的事情,那么任何建议都将不胜感激。

$cmd = "nohup wget -q <-url here-> -O /dev/null 2>&1 &")";
$exec = exec( 'bash -c "'.$cmd.'"' );

note the -O flag, with which you tell wget where to save the downloaded file. 注意-O标志,使用该标志告诉wget将下载的文件保存在何处。 with this, you direct it to /dev/null and therefore delete it. 这样,您将其定向到/ dev / null并因此将其删除。

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

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