gpt4 book ai didi

php - 清除启动浏览器缓存

转载 作者:行者123 更新时间:2023-12-01 08:25:28 25 4
gpt4 key购买 nike

我正在尝试可视化网站速度分析。作为 headless 浏览器,我使用 Splash 3.2 ...不幸的是,我在获取正确的 har 文件时遇到问题。

第一个请求看起来不错,在第二个请求之后我只收到未缓存的请求。

我尝试通过向 _gc 端点发出 post 请求来清空缓存,遗憾的是没有成功。

我的 curl 请求:

$url = 'http://localhost:8050/render.har?url=' . esc_url( $url ) .'&response_body=1&wait=5&timeout=10';
$cache_url = 'http://localhost:8050/_gc';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $cache_url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,"cached_args_removed=1");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($curl);

curl_reset($curl);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($curl);
curl_close($curl);

_gc请求的结果:

{"cached_args_removed": 0, "pyobjects_collected": 1269, "status": "ok"}

之后,我尝试使用 --disable-browser-caches 启动 Splash 以获得正确的输出,但 Splash 不会缓存任何内容,因此会向同一文件发出许多请求(如果它们发生多次)。

是否有另一种方法可以在渲染之前刷新浏览器缓存,或者我应该更喜欢使用其他 headless 浏览器(推荐)?

最佳答案

@托比亚斯

您提到您正在使用splash 版本3.2

我是 PR 821 的作者其中引入了 --disable-browser-caches ,并根据 the changelog ,该功能在splash 3.3版本中落地。因此,请升级到启动版本 3.3,您应该能够使用该功能。

关于php - 清除启动浏览器缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54281075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com