简体   繁体   中英

Using exec() to run a php file from a php file fails

I intent to have one PHP file run another PHP file. The second file has a rather long runtime. That's why I do not simply use include or require. Instead I use the following operation.

exec('php5 /full/path/to/the/other/file.php > /dev/null 2> /dev/null < /dev/null &');

But instead of running the intended file, the file is instead calling itself again, thery calling itself again, and so on, until I remove the exec() command from the file.

If I take the content of the exec() command and run it on the command line, it works as intended.

What am I doing wrong?

Try putting the full path of your php5 execulatable (whereis php5). exec() doesn't run in the same environment that you have when you're at a shell, so the PATH environment variable might not have the path of php5 in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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