【问题标题】:PHP include array-content from filePHP包含文件中的数组内容
【发布时间】:2020-06-28 10:46:06
【问题描述】:

我正在尝试优化日志性能。

到目前为止,我使用 Fileappend() 创建日志 & file() + foreach line + explode() 来显示它。

我想得到什么:

<?php
    $tmp = [
    include("log.php")
    ];

    print_r($tmp); 
?>

log.php:

"test"=>"haus",
"test2"=>"haus2",

这将使思考更快、更容易。有什么想法吗?

【问题讨论】:

  • 如果您可以将日志文件格式更改为 ini 文件格式,则可以使用stackoverflow.com/questions/34814054/… 中的代码。不过,这确实假定了键的唯一值。
  • 我认为解析 ini 的性能与我的旧解决方案一样糟糕
  • 我不知道 - 我无法比较两者。但我希望 ini 文件解析速度更快 - 多少我不知道。

标签: php arrays include


【解决方案1】:

我想可以这样做:

log.php:

<?php

return [
    "test"=>"haus",
    "test2"=>"haus2",
];

在你的文件中:

<?php

$tmp = include("log.php");

print_r($tmp); 

【讨论】:

  • 是的,但我想使用 Fileappend 作为日志。我无法每次都将整个日志重写到磁盘。
猜你喜欢
  • 2011-11-30
  • 1970-01-01
  • 2016-10-05
  • 2013-09-19
  • 1970-01-01
  • 1970-01-01
  • 2021-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多