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.

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

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作