3

我在 CentOS 上运行 Apache 服务器,并希望能够使用以下命令从受保护的页面重新启动网络服务器:

PHP:

<?php
ignore_user_abort(true);
shell_exec('sh sh/restart.sh');
?>

重启.sh:

service httpd restart

我的问题是如果 web 服务器关闭并且 PHP 停止执行,sh 脚本会继续运行以使 web 服务器重新联机吗?

4

3 回答 3

0

If your PHP runs as apache module, then once you kill httpd your script will be terminated instantly. So you need to delegate restart to i.e. command line script (called using exec() or shell_exec())

于 2012-11-04T19:18:27.157 回答
0

你应该没问题,因为 Apache 直到发出命令后才会关闭。但是,如果您真的想要安全,请使用nohup

shell_exec('nohup sh sh/restart.sh');
于 2012-11-04T19:13:25.893 回答
0

您也许可以在命令末尾添加一个 & 。这将分叉该进程并在后台运行它。这样它就不会依赖于仍在运行的 apache。

shell_exec('sh sh/restart.sh &');

如果这可行,则不需要 ignore_user_abort()。

于 2012-11-05T03:02:36.913 回答