简体   繁体   English

启动一个可以稍后通过PHP访问的变量的Apache服务?

[英]Starting Apache service with a variable that can be later accessed via PHP?

I have a need to start the Apache service with a parameter so that I can later access that parameter via PHP. 我需要使用一个参数启动Apache服务,以便以后可以通过PHP访问该参数。 Is this possible? 这可能吗?

pass the parameter to httpd with the -C or -c ( process the configuration directive before/after reading config files ) command line option and the SetEnv directive: 使用-C-c在读取配置文件之前/之后处理配置指令命令行选项SetEnv指令将参数传递给httpd:

httpd -C "SetEnv FOO bar"

FOO can now be accessed from PHP like so: 现在可以从PHP访问FOO ,如下所示:

<?php
print getenv('FOO');

prints 版画

bar

You can set an environment variable. 您可以设置环境变量。 See also: getenv 另请参阅: getenv

Based on the comments on your question, I'd say that using shared memory is an acceptable alternative. 基于对您的问题的评论,我想说使用共享内存是可以接受的选择。 Take a look at shmop_open() et alia. 看看shmop_open()等。

使用-c启动httpd程序时,它会采用“指令”,因此请尝试使用该指令和SetEnv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM