PHP parse_ini_file是否可以在URL上工作? [英] PHP parse_ini_file work on URL?
问题描述
PHP方法 parse_ini_file 是否可以在云中托管的INI文件上运行?现在,我有一个配置文件位于我的每台App服务器中,在任何给定时间,配置文件的大小都可以在4-8之间.对于每个服务器,手动进行配置更改都非常痛苦.
Does the PHP method parse_ini_file work on an INI file hosted in the cloud? Right now, I have a config file that sits in every single one of my App servers, which could be anywhere from 4-8 at any given time. Making a config change is brutally painful to do by hand for each server.
我尝试了以下操作,但无济于事:
I've tried the following but to no avail:
$handle = fopen('https://blah.com/config.ini', 'r');
$ini = parse_ini_file($handle, true);
但我收到此错误:
Warning: parse_ini_file() expects parameter 1 to be a valid path, resource given
这甚至有可能吗?有什么想法吗?
Is this even possible? Any ideas?
推荐答案
fopen()
并非那样使用.尝试 file_get_contents():
fopen()
is not used like that. Try file_get_contents():
$content = file_get_contents('https://blah.com/config.ini');
$ini = parse_ini_string($content, true);
这可能会起作用(未经测试):
This may work instead (not tested):
$ini = parse_ini_file('https://blah.com/config.ini', true);
无论哪种情况,都需要在php.ini
中启用allow_url_fopen
.
In either case allow_url_fopen
needs to be enabled in php.ini
.
这篇关于PHP parse_ini_file是否可以在URL上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!