douyong6589 2018-07-19 17:47
浏览 35
已采纳

在php中缓存包含的远程文件

I am including a remote file after making

allow_url_include = On

The file is included using include_once in file.php

include_once ("http://abcd.com/func.php");

I am using simple LAMP stack.

My question is that for every request which comes to the server and uses file.php, func.php will be pulled from abcd.com. Within a request if file.php is included many times in other files will func.php be pulled every time?

  • 写回答

1条回答 默认 最新

  • duanhuayong6687 2018-07-19 18:24
    关注

    The _once means you will load the file once per request. But will load it again on a new request. If you want to cache some response of this file make a return in that included file and save the result anywhere you like. For example in a textfile (i.e. as JSON-string). On the next request you check if that file exists.

    However saving in a textfile may not be the most perfomant way to do this, but probably faster than requesting this file every time. Have a look at Memcache

    Include into a var: $data = include_once('...'); (include has to have a return)

    $data = cached_include('..') (the function you write to get cached data)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集