【问题标题】:PHP After Apache Shuts Down?Apache关闭后的PHP?
【发布时间】:2012-10-24 16:24:54
【问题描述】:

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

PHP:

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

重启.sh:

service httpd restart

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

【问题讨论】:

  • 你尝试的时候发生了什么?
  • 运行service httpd restart 需要root,不是吗?我希望你的 PHP 页面没有以 root 权限运行。
  • PAM 包可能允许他以 root 身份进行身份验证来执行此操作。 pecl.php.net/package/PAM

标签: php apache centos


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    如果您的 PHP 作为 apache 模块运行,那么一旦您终止 httpd,您的脚本将立即终止。所以你需要将重启委托给命令行脚本(使用exec()shell_exec()调用)

    【讨论】:

      【解决方案3】:

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

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

      如果这可行,您应该不需要 ignore_user_abort()。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-05
        • 1970-01-01
        • 1970-01-01
        • 2012-10-29
        • 2013-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多