php 将数组结果作为返回值保存到php文件中

    xiaoxiao2021-12-14  21

    经常在处理一些数据是会把一些结果json_encode然后保存到文本中,用的时候再取出来json_decode执行遍历等操作,

    在一次开发接口过程中发现整个接口性能不佳,请求很慢,同事指出其中一条优化建议是,直接保存在php文件中然后直接返回 数组,省去了读取文本json_decode的过程

     保存数据的过程中

    saveData.php 处理到

     $content='<?php return '.var_export($bigPic,true).';';

        if(md5($oldcontent)!=md5($content)){         file_put_contents("content.php",$content);    }

       

    调用数据时

     $data=include("saveData.php");

    在content.php格式如下:

    <?php return array (

    "0"=>value1,

    "1"=>value2

    ........................

    );

    转载请注明原文地址: https://ju.6miu.com/read-963835.html

    最新回复(0)