简体   繁体   English

将静态数据存储在JSON文件还是PHP文件本身中?

[英]Storing static data in JSON file vs PHP file itself?

I'm writing a web service in PHP using the slim framework. 我正在使用苗条的框架在PHP中编写Web服务。 Any request made to any endpoint will only be allowed if (a) the request is coming from a list of IPs (b) the HTTP request header contains a secret string, which is static (I know this isn't the best way to secure a web service, but this service is mostly for internal use and we don't need anything more complicated). 仅当(a)请求来自IP列表时(b)HTTP请求标头包含一个秘密字符串(是静态的)(我知道这不是确保安全的最佳方法),才会向任何端点发出任何请求网络服务,但该服务主要供内部使用,我们不需要任何更复杂的东西)。

Should I store the list of IPs and the shared secret in a JSON file or should I initialize the array of IPs and the shared secret string in the PHP script itself? 我应该将IP列表和共享机密存储在JSON文件中,还是应该在PHP脚本本身中初始化IP数组和共享机密字符串? Storing it in a JSON file would mean that the data would have to be read from disk on every HTTP request. 将其存储在JSON文件中将意味着必须在每个HTTP请求中从磁盘读取数据。 I'm assuming this is bad as far as performance is concerned? 我以为就性能而言这是不好的?

您可以定义具有所有IP的const文件: https : //secure.php.net/manual/it/function.define.php,然后将其与require

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

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