douwei9973 2019-06-08 05:18
浏览 279
已采纳

base64_encode的问题,这使我的网站php速度变慢

I have use image src encryption with base64_encode but that code slower my site but when I put this code it makes my site slower. so do anybody has any solution to make my site faster with this type of encryption. I have put my code below.

<?php
   while ($user = mysqli_fetch_array($queryResult, MYSQLI_ASSOC)){
      if ($user["main_picture"]){
       $imageData = base64_encode(file_get_contents($user["main_picture"]));
       $result .= '<td><div class="user_image_container"><img src="data:image/jpeg;base64,'.$imageData.'"></img></div></td>';
      }
      else{
          $result .= '<td></td>';
      }
?>

can anybody help me in this.

  • 写回答

1条回答 默认 最新

  • duanmengsuo9302 2019-06-08 06:02
    关注

    When you load your page with this code the PHP interpreter has to finish fetching the image over the network before it can interpret the rest of the page, which adds time.

    If you were to load the page without this code and use a direct link to the image, the page itself would load a lot faster and then the browser would load the image.

    Potential workaround: use a database to store single-use tokens that map to to images. When a user loads the page, generate a token (which will be quicker than pulling the image) and have the image src point to an image-serving endpoint that you set up that checks the token, marks it as used, fetches the file and then sends the image. You might run into problems with caching if you want it to be truly single use, but it does at least hide the source of the image.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!