是否可以在 apache 启动时启动 php 脚本? [英] Is it possible to launch a php script at apache startup?

查看:45
本文介绍了是否可以在 apache 启动时启动 php 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我想知道是否可以在重新启动apache后自动启动PHP脚本.

As the title says, I want to know if it is be possible to automatically launch a PHP script when a restart of apache is done.

更多信息

我会尽力解释这样做的目的.我们目前正在重构我们的应用程序,我们暂时会被两种不同的配置文件系统困住,直到所有应用程序流程都被重构(可能需要一年多的时间).旧系统使用 key=value 格式的简单平面文件(即 www.conf),而新系统将使用可缓存的 php 文件(即 www.php).我们需要将在 www.conf 中所做的任何配置更改复制到 www.php.

I will try to explain what is the purpose of this, the best I can. We are currently refactoring our application and we'll be stuck with 2 differents configuration file system for the time being, until all of the application flows are refactored (might take more than a year). The old one is using simple flat file in the key=value format (i.e. www.conf), while the new system will use cacheable php files (i.e. www.php). We need to replicate to www.php any config changes made in www.conf.

由于每当 www.conf 中的配置发生更改时 Apache 都会重新启动,因此我认为启动 PHP 脚本可能是一个很好的解决方法,该脚本会将 www.conf 复制到 www.php.

Since Apache gets restarted whenever there is a config change in www.conf, I thought it might be a good workaround solution to launch a PHP script, that would replicate the www.conf to www.php.

推荐答案

您需要为您的 apache 修改启动脚本.

You need to modify you startup script for your apache.

打开你的启动脚本,它应该在/etc/init.d/apache 或 apache2

Open your startup script, it should be in /etc/init.d/apache or apache2

搜索开始/重新启动部分并为您的 PHP 脚本添加 cli 调用.

Search for the start / restart section and add your cli call for your PHP script.

示例:

    restart)
            [..]
            php -q /tmp/myscript.php &
            ;;

其中/tmp/myscript.php 是您要启动的 php 脚本.

Where /tmp/myscript.php is your php script that you want to launch.

&"最后将在后台启动脚本,因此您的启动不会等到您的 php 脚本结束.如果您想等到它结束,请删除 &.

The "&" at the end will start the script in the background so your startup will not wait until your php script has ended. If you want to wait until it has ended, remove the &.

你不应该把这样的东西放到你的启动脚本中,可能有更好的解决方案.正在努力实现什么?

You should not put such thing into your startup scripts, there might be better solutions. What are trying to achieve?

这篇关于是否可以在 apache 启动时启动 php 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆