在一台服务器上运行 fopen/file_get_contents 时返回乱码,但在另一台服务器上则不返回乱码
我正在构建一个脚本,通过读取给定页面的内容并在其中查找预定义的字符串来检查网站是否已启动(如果网站已关闭,则不会找到该字符串)。
我正在使用 file_get_contents 函数读取页面内容,问题是在极少数情况下收到的内容只是乱码。我尝试对 fopen 甚至curl 做同样的事情。所有功能都变得乱七八糟。一开始我以为是因为编码问题(页面是UTF8),我尝试使用所有参数,但似乎并非如此。
当我决定在另一台服务器上测试代码时,整个事情变得更加奇怪。效果非常好!在我的开发站上返回乱码的相同页面在我的其他网络服务器上运行时返回可读文本。
两个站都安装了最新的 WAMP 作为开发环境,您对导致此问题的原因有什么建议吗?
I'm building a script to check whether sites are up or not by reading a given page's content and looking for a predefined string in it (if the site is down the string won't be found).
I'm reading a page content with the function file_get_contents, the problem is that at some rare cases the content received is simply Gibberish. I tried to do the same with fopen and even with curl. Getting gibberish with all functions. At the beginning I thought its because of encoding issues (the pages are UTF8) and I tried to play with all the parameters, but it doesn't seem to be it.
The whole thing became much weirder when I decided to test the code on another server. It worked perfectly! the same pages which return gibberish on my dev station return readable text when being run on my other web server.
Both stations have the latest WAMP installed as a dev environment, do you have any suggestions to what can cause this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我所说,它可能是压缩输出,使用此函数并通过它传递“乱码”。如果这不是问题,请让我知道我将删除此答案
编辑:
不确定,奇怪的设置。我之前在某些网站上遇到过这个问题
SetEnv no-gzip dont-vary
在 .htaccess 文件中将其关闭as i said it could be a gzipped output, use this function and pass that "gibberish" through it. if its not the issue let me know ill remove this answer
EDIT:
not sure, odd settings. ive run into this problem before with some sites
SetEnv no-gzip dont-vary
in a .htaccess file turns it off