doufu2396 2018-09-03 23:13
浏览 69
已采纳

将Cache-Control年龄转换为天,分或秒?

I need to develop a code that identifies the cache time of each file in a given URL like this tool

For that I'm using PHP with CURL:

$website = 'https://stackoverflow.com';

$ch = curl_init($website);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$resp = curl_exec($ch);
var_dump($resp);

But in the response I don´t see the age of cache files and the cache control is target as private.

To work around this problem, I had to grab the link from each image file, javascript, css existing in the body of the page and run the same CURL code as above.

And finally the cache-control would be shown, some show a huge date (max-age=315360000) others show a small date (max-age=604800), now remains to know how can I convert and identify when cache-control is referring to days, minutes, years or seconds ?

  • 写回答

1条回答 默认 最新

  • dongpu9481 2018-09-03 23:26
    关注

    one can convert from seconds to human-readable format alike this:

    sprintf('%02d:%02d:%02d', ($s/3600), ($s/60%60), $s%60);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作