php file_exists不起作用(同一浏览器中的多次执行)
我试图理解为什么此脚本不起作用时,当我在同一浏览器或浏览器选项卡中同时执行脚本时,第二个脚本看不到创建的文件“/tmp/monkey.tmp”(php7.4-fpm + nginx ,默认配置,启用OPCACHE)
,一旦我使用两个不同的浏览器,它就可以像预期的那样工作,如果我同时执行相同的脚本/URL,一个带有随机数据的脚本,例如url?_ = monkey,它的工作方式如预期,问题是,问题是,问题是同一浏览器中的同一个URL,我不明白为什么
$tmpfile = '/tmp/monkey.tmp';
clearstatcache();
if(file_exists($tmpfile))
{
die('file exist');
}
else
{
file_put_contents($tmpfile, 'blabla');
}
sleep(20);
exit;
I'm trying to understand why this script doesn't work, when I execute script simultaneously in same browser or browser tab, second script do not see the created file "/tmp/monkey.tmp" (php7.4-fpm + nginx, default config, opcache enabled)
As soon as I used two different browsers, it works like expected, if I execute same script/URL simultaneously and one script with random data for example URL?_=monkey, it works like expected, problem is same URL in same browser, I dont understand why
$tmpfile = '/tmp/monkey.tmp';
clearstatcache();
if(file_exists($tmpfile))
{
die('file exist');
}
else
{
file_put_contents($tmpfile, 'blabla');
}
sleep(20);
exit;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当使用浏览器调试时,PHP可能很棘手,因为它们很可能会缓存PHP页面,这不是通缉的Bahaviour。
我的猜测是浏览器或Web服务器缓存了网站,这就是为什么您看不到更改的原因。
但是在另一个没有缓存的浏览器上。
这也解释了当Cahnign的某些部分URL时,您为什么会看到同一浏览器中的更改,因为浏览器将其视为另一个页面,无法使用它的高速缓存并转到服务器。
要调试您可以尝试以下内容:
尝试安装插件以清除缓存。
为了停止此操作,您可以尝试在浏览器Devtools中禁用此站点的缓存。
或在HTML中设置Matadata缓存时间,以免缓存站点。
或通过JS运行请求,然后将结果打印到页面上。
如果缓存清除后,您仍然看不到页面的存在。
它可能是网络服务器缓存响应。
这不太可能...
Php can be tricky, when debugging with browsers because they most likely cache the php page, tho that is not the wanted bahaviour.
My guess is the browser or webserver cached the site and that is why you don't see the change.
But on the other Browser that didn't cache does.
That also explains why you see the change in the same browser when cahnign some part of the url, because the browser treats it as another page and can not use it's cache and goes to the server.
To debug u can try the following:
Try to install a plugin to clear the cache.
To stop this you can try and disable caching for this site in your browsers devtools.
Or set matadata cache time in the html to never cache the site.
Or run the request via Js that then prints the result to the page.
If after the cache clear you still don't see the page exists.
It maybe the webserver caching the response.
Tho thats unlikely...