PHP fopen函数超时? [英] PHP fopen function timed out?

查看:272
本文介绍了PHP fopen函数超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何知道为什么fopen如果文件在我的服务器上并且我知道网址正确的原因会超时吗?

any idea why fopen would timeout for a file if it is on my server and I know the url is correct?

更新:对不起,我应该提到这是在php中. 代码是:

update: sorry, i should have mentioned this is in php. the code is:

fopen($url, 'r');

如果我为文件输入了相对路径,则它起作用,但是如果$ url是服务器中的url,则它不起作用(但它适用于google.com).感谢您的帮助.

It works if i put in a relative path for the file, but not if $url is a url in my server (but it works for google.com). Thanks for the help.

Alaitnik的回答是正确的.仅当我通过以太网接口访问我自己的服务器文件时,才会出现此问题.我怎样才能解决这个问题?我需要能够从以太网接口访问文件,因为url是动态加载的(它是由wordpress cms生成的,因此从技术上讲,url在我的服务器上不存在)

Alaitnik's answer was right. The problem only appears when i access my own server files through the ethernet interface. How can I fix this? I need to be able to access the file from the ethernet interface because the url loads dynamically (it's generated from a wordpress cms, so the url doesn't technically exist as a file on my server)

推荐答案

您可以使用 ini_set('default_socket_timeout',2); 在打开fopen $ url之前.这实际上设置了默认的套接字连接timout,但没有响应. Stream_set_timeout设置通过fopn或套接字打开函数建立的流的超时. 试试这个可能对您有帮助.

you can use ini_set('default_socket_timeout',2); before opening the fopen $url . This actually set the default socket connection timout without responding. Stream_set_timeout sets time out on the stream that is established via fopn or socket opening functions. Try this may be helpful for you.

这篇关于PHP fopen函数超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆