开发者

php exec multiple commands, apache restart

I have to run 2 commands through exec(); the first command is a wrapper calling for (Plesk panel) subsription, the second is also a plesk command,for dns.

Note: After i execute an add subscription, the apache WILL RESTART!,

So my Question is: can i call the exec somehow, to execute both co开发者_高级运维mmands at linux side without loss of the second command?

Ex:

exec(("/wrapper2 3 --create ... && /wrapper2 4 --update-soa example.com ... ) > /dev/null 2>&1 );

Php will send both commands to linux to execute, or it will restart apache after the first command, and then i can't execute the second command?

Thanks


Um... I'm thinking bad deal. Generally it is a bad idea for a process to tell its parent to restart while the process needs to keep running. But, even if it were a good idea -- Apache is the parent process of PHP in that context (do ps -A, you'll not see PHP), I can't imagine that it would let you restart it and keep running at the same time.

I'd approach it this way: if you can bridge a delay, then have a cron job look for whether a specific file exists, if it does, then execute the two command that you need it to. At a worse-case scenario, make PHP output a file which has the two commands you want run and then have cron run that file.


Well from my understanding the issue lies in the fact that Apache is going to be the parent of the script that is running, when Apache gets shut down so will the script.

Barring that you can deal with a sort of derp-y setup, you can set up a cron job that looks for when it needs to restart the server (either a file you created via touch or something from PHP), which can handle everything outside of the context of Apache's process.

A sort-of-dirty idea. :(


Put the commands in a shell script and execute that script. It's less complicated and just in case you can call it with other tools as well like on apache restart or via cron.


I think why the apache restart is your command executes too long or cost to much system resource and makes apache sub process exits. Try using fastcgi mode instead of mod_php.

You can make a shell file to execute two commands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜