由于线上和线下的环境不同,通过一个后台配置模板和定义一个php扩展函数string lg_config(string ip,string project,string name)来解决此问题
1.mkdir -p /data_disk/webdata/php_extension
2.touch /data_disk/webdata/php_extension/languang_config.def
3.vim /data_disk/webdata/php_extension/languang_config.def
string lg_config(string ip,string project,string name)
4.cd php5/ext
5.vim config.m4
去掉中间一行,和前后一行的dl
PHP_ARG_ENABLE(languang_config_module, whether to enable languang_config_module support,
[ --enable-languang_config_module Enable languang_config_module support])
6.vim languang_config_module.c
PHP_FUNCTION(lg_config)
{
char *ip = NULL;
char *project = NULL;
char *name = NULL;
int argc = ZEND_NUM_ARGS();
int ip_len;
int project_len;
int name_len;
char *ret_str;
if (zend_parse_parameters(argc TSRMLS_CC, "sss", &ip, &ip_len, &project, &project_len, &name, &name_len) == FAILURE)
return;
if (strcmp(ip,"112.1.1.1") == 0){
if (strcmp(name,"mysql") == 0){
ret_str = "config_test/config_db.inc.php";
}else if(strcmp(name,"cache") == 0){
ret_str = "config_test/config_cache.inc.php";
}else if(strcmp(name,"queue") == 0){
ret_str = "config_test/config_queue.inc.php";
}else{
ret_str = "config_test/config_other.inc.php";
}
}else{
if (strcmp(name,"mysql") == 0){
ret_str = "config/config_db.inc.php";
}else if(strcmp(name,"cache") == 0){
ret_str = "config/config_cache.inc.php";
}else if(strcmp(name,"queue") == 0){
ret_str = "config/config_queue.inc.php";
}else{
ret_str = "config/config_other.inc.php";
}
}
RETURN_STRING(ret_str,1);
}
7./usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make && make install
vim /usr/local/webserver/php/etc/php.ini (加入扩展)
extension = "languang_config_module.so"
/usr/local/webserver/php/sbin/php-fpm reload
8.验证是否成功