php执行多个命令,apache重启

发布于 2024-11-16 14:51:21 字数 413 浏览 3 评论 0原文

我必须通过 exec() 运行 2 个命令; 第一个命令是一个调用(Plesk 面板)订阅的包装器, 第二个也是 plesk 命令,用于 dns。

注意:在我执行添加订阅后,apache 将重新启动!,

所以我的问题是: 我可以以某种方式调用 exec,在 linux 端执行这两个命令而不丢失第二个命令吗?

例如:

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

Php 会将这两个命令发送到 linux 来执行,或者在第一个命令后它将重新启动 apache,然后我无法执行第二个命令?

谢谢

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 commands 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

要走干脆点 2024-11-23 14:51:21

嗯...我想这很糟糕。一般来说,当进程需要继续运行时,告诉其父进程重新启动是一个坏主意。但是,即使这是一个好主意 - Apache 是 PHP 在该上下文中的父进程(执行 ps -A,您将看不到 PHP),我无法想象它会让你重新启动它并同时继续运行。

我会这样处理:如果您可以桥接延迟,则让 cron 作业查找特定文件是否存在,如果存在,则执行您需要的两个命令。在最坏的情况下,让 PHP 输出一个文件,其中包含您要运行的两个命令,然后让 cron 运行该文件。

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.

影子的影子 2024-11-23 14:51:21

根据我的理解,问题在于 Apache 将成为正在运行的脚本的父级,当 Apache 关闭时,脚本也会关闭。

除非您可以处理某种 derp-y 设置,否则您可以设置一个 cron 作业来查找何时需要重新启动服务器(通过 touch 创建的文件或来自 PHP 的文件),它可以处理外部的所有内容Apache 进程的上下文。

有点肮脏的想法。 :(

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. :(

叹梦 2024-11-23 14:51:21

将命令放入 shell 脚本中并执行该脚本。它不那么复杂,以防万一您也可以使用其他工具调用它,例如在 apache 重新启动或通过 cron 时。

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.

分分钟 2024-11-23 14:51:21

我认为为什么 apache 重新启动是您的命令执行时间太长或消耗了太多系统资源并使 apache 子进程退出。
尝试使用 fastcgi 模式而不是 mod_php。

您可以创建一个 shell 文件来执行两个命令。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文