gpt4 book ai didi

php - 缓存包含或需要的文件以便可以反复使用?

转载 作者:搜寻专家 更新时间:2023-10-31 22:08:40 25 4
gpt4 key购买 nike

我用 PHP 渲染了一个 HTML 表格,看起来有点像这样:

--------------------------------------------------
| title | description | actions |
-------------------------------------------------|
| title1 | desc1 | edit / delete |
| title2 | desc2 | edit / delete |
| title3 | desc3 | edit / delete |
| title4 | desc4 | edit / delete |
--------------------------------------------------

代码是这样工作的(精简版!没有theadtbody 等等):

<table>
<?php foreach ( $tableData as $row ): ?>
<tr>

<!-- Render columns (title, description)
<?php foreach ( $columnData as $column ): ?>
<td>
<?= $row[$column['name']]; ?>
</td>
<?php endforeach; ?>

<!-- Render actions -->
<?php foreach ( $actions as $action ): ?>
<td>
<?= include($action); // include the proper action button! ?>
</td>
<? endforeach; ?>

</tr>
<?php endforeach; ?>
</table>

这给了我想要的结果。但我对此只有一个问题。当我有 1000 多条记录时,它会变得有点慢。我已经注意到这是因为我正在为每个表行执行 include。当我删除 include 时,一切都运行得非常快。

included 文件包含一些 PHP 逻辑。所以我不能只执行 file_get_contents。嗯,我可以,但是我必须使用 eval() 来解析内容。但我宁愿根本不使用该功能。

所以现在我想知道是否有可能以某种方式缓存包含的文件?这样 PHP 就不必主动地一遍又一遍地包含实际文件,而是从缓存中获取它?这样的事情可能吗?

或者有更好的选择吗?

最佳答案

您可以将所有操作(功能)放在一个文件中,并一次包含该文件。在循环中,您将根据它们的名称调用不同的函数。 Variable function example .

关于php - 缓存包含或需要的文件以便可以反复使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14788405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com