fopen有尺寸限制吗?

时间:2009-09-12 20:35:33

标签: php fopen

我在php中使用fopen时遇到了问题。

如果我手动打开所需的网址,我会得到:

OK,13:24:34.236 INFO [10] org.mortbay.http.SocketListener - Started SocketListener on 0.0.0.0:4443 13:24:34.236 INFO [10] org.mortbay.util.Container - Started org.mortbay.jetty.Server@52fe85 13:24:39.251 INFO [11] org.mortbay.util.Credential - Checking Resource aliases 13:24:39.251 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: getNewBrowserSession[*firefox, http://dev.REPLACED.com] on session null 13:24:39.251 INFO [11] org.openqa.selenium.server.BrowserSessionFactory - creating new remote session 13:24:39.939 INFO [11] org.openqa.selenium.server.BrowserSessionFactory - Allocated session 179f69cb121941e3b45c7312664de890 for http://dev.REPLACED.com, launching... 13:24:40.048 INFO [11] org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher - Preparing Firefox profile... 13:24:47.751 INFO [11] org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher - Launching Firefox... 13:25:01.751 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK,179f69cb121941e3b45c7312664de890 on session 179f69cb121941e3b45c7312664de890 13:25:01.861 INFO [18] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: windowMaximize[, ] on session 179f69cb121941e3b45c7312664de890 13:25:03.657 INFO [18] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:04.267 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: open[index.php?module=authsystem&func=logout, ] on session 179f69cb121941e3b45c7312664de890 13:25:11.064 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:11.673 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: waitForPageToLoad[30000, ] on session 179f69cb121941e3b45c7312664de890 13:25:11.814 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:12.407 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: type[uname4, Selenium] on session 179f69cb121941e3b45c7312664de890 13:25:12.423 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:13.079 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: type[pass4, casetester] on session 179f69cb121941e3b45c7312664de890 13:25:13.111 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:13.704 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: click[rememberme4, ] on session 179f69cb121941e3b45c7312664de890 13:25:13.782 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:14.361 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: click[//input[@value='Log In'], ] on session 179f69cb121941e3b45c7312664de890 13:25:14.517 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:15.095 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: waitForPageToLoad[30000, ] on session 179f69cb121941e3b45c7312664de890 13:25:16.001 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:16.642 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: click[link=REPLACED, ] on session 179f69cb121941e3b45c7312664de890 13:25:16.751 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:17.345 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: waitForPageToLoad[30000, ] on session 179f69cb121941e3b45c7312664de890 13:25:19.532 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Got result: OK on session 179f69cb121941e3b45c7312664de890 13:25:26.204 INFO [11] org.openqa.selenium.server.SeleniumDriverResourceHandler - Command request: retrieveLastRemoteControlLogs[, ] on session 179f69cb121941e3b45c7312664de890

现在,如果我使用fopen打开该URL:

echo fopen($myurl, "r");

显示的内容在1330个字符中被删除... 是否有限制我应该按预期收到整个内容?

2 个答案:

答案 0 :(得分:4)

首先:

echo fopen($myurl, "r");

显然不会起作用。我认为你的意思是:

$handle = fopen($myurl, "r");
echo(fread($handle, $some_size));
fclose($handle);

在那种情况下,你做错了。 fread()不保证在一次调用中返回所有数据;有时您需要多次调用它才能获得整个输入。如果远程HTTP服务器使用Transfer-Encoding:chunked。

,则尤其如此

有关详细信息,请参阅the fread() documentation。引用文档:

  

当从任何非常规本地文件读取时,例如读取远程文件时返回的流或从popen()和fsockopen()读取时,读取将在数据包可用后停止。这意味着您应该以块的形式收集数据,如下面的示例所示。

$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);

更简单的解决方案是使用file _ get _ contents()。但是,此函数会将整个文件写入单个字符串,这可能会也可能不会影响性能,具体取决于您对网页输入的处理方式。

答案 1 :(得分:1)

尝试将output buffering从ON更改为设定大小。例如

output_buffering = 4096