For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2007 > filesize() not reading http pages









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author filesize() not reading http pages
Eric Layman

2007-02-01, 3:59 am

Hi,

According to the PHP documentation:

it stated that as of php5, filesize supports the reading of remote html
files:

http://php.net/manual/en/function.filesize.php

But I have tried the following:
echo filesize("http://www.yahoo.com/");

It returned me this error:

Warning: filesize() [function.filesize]: stat failed for..blah blah

Anyone have this same problem?

Yes. Im using PHP5

..



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
J.O. Aho

2007-02-01, 3:59 am

Eric Layman wrote:
> Hi,
>
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote html
> files:
>
> http://php.net/manual/en/function.filesize.php
>
> But I have tried the following:
> echo filesize("http://www.yahoo.com/");
>
> It returned me this error:
>
> Warning: filesize() [function.filesize]: stat failed for..blah blah
>
> Anyone have this same problem?
>
> Yes. Im using PHP5


Maybe your php has disable the remote file reading, check your php.ini.

--

//Aho
Eric Layman

2007-02-01, 3:59 am

HI,

Thakns for the reply.

I have checked this setting in my php.ini

allow_url_fopen = On

It is ON be default.

"J.O. Aho" <user@example.net> wrote in message
news:52djb1F1ngqghU1@mid.individual.net...
> Eric Layman wrote:
>
> Maybe your php has disable the remote file reading, check your php.ini.
>
> --
>
> //Aho




Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
J.O. Aho

2007-02-01, 7:59 am

Eric Layman wrote:

<cut away a bit relevant info, but didn't feel to fix the troubles top
posting causes>


> I have checked this setting in my php.ini
> allow_url_fopen = On


Did read a bit on the online manual,
http://php.net/manual/en/function.filesize.php and it says that you need
a wrapper to be able to read the filesize remotly, see the following
page for more info about wrappershttp://www.php.net/manual/en/wrappers.php

--

//Aho
Janwillem Borleffs

2007-02-01, 7:59 am

Eric Layman schreef:
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote html
> files:
>
> http://php.net/manual/en/function.filesize.php
>


It also states that you should look in the HTTP wrapper section of the
appendix to see if it's supported by the stat() function. Like this
function, filesize() only works on local files and doesn't support the
HTTP protocol.

If you want to check the size of a remote file, you could do something
as follows:

$fp = fsockopen('www.google.com', 80);
fputs($fp, "HEAD / HTTP/1.0\r\n");
fputs($fp, "Host: www.google.com\r\n\r\n");

$size = 0;
while (!feof($fp)) {
$line = fgets($fp, 1024);
if (preg_match('/content-length:\s*(\d+)/i', $line, $m)) {
$size = $m[1];
break;
}
}
fclose($fp);

print "Size of Google homepage HTML: $size bytes";


JW
Kim André Akerĝ

2007-02-01, 6:58 pm

Eric Layman wrote:

> Hi,
>
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote
> html files:
>
> http://php.net/manual/en/function.filesize.php
>
> But I have tried the following:
> echo filesize("http://www.yahoo.com/");
>
> It returned me this error:
>
> Warning: filesize() [function.filesize]: stat failed for..blah blah
>
> Anyone have this same problem?
>
> Yes. Im using PHP5


It also says in the manual (you have to read it carefully):

> As of PHP 5.0.0 this function can also be used with *some* URL
> wrappers. Refer to Appendix M for a listing of which wrappers support
> stat() family of functionality.


To summarize, these wrappers support the use of stat():

Filesystem Yes
Socket No
HTTP and HTTPS No
FTP and FTPS Partial [1]
PHP input/output streams php://memory and php://temp only
Compression Streams No [2]
Data (RFC 2397) No
Secure Shell 2 ssh2.ftp only
Audio Streams No
Process Interaction Streams No
http://www.php.net/manual/en/wrappers.php

[1] As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(),
and is_dir() elements only. As of PHP 5.1.0: filemtime().
[2] Use the normal file:// wrapper to stat compressed files.

--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Eric Layman

2007-02-01, 6:58 pm

Thank you Kim!


"Kim André Akerĝ" <kimandre@NOSPAMbetadome.com> wrote in message
news:52eglbF1o4gaoU1@mid.individual.net...
> Eric Layman wrote:
>
>
> It also says in the manual (you have to read it carefully):
>
>
> To summarize, these wrappers support the use of stat():
>
> Filesystem Yes
> Socket No
> HTTP and HTTPS No
> FTP and FTPS Partial [1]
> PHP input/output streams php://memory and php://temp only
> Compression Streams No [2]
> Data (RFC 2397) No
> Secure Shell 2 ssh2.ftp only
> Audio Streams No
> Process Interaction Streams No
> http://www.php.net/manual/en/wrappers.php
>
> [1] As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(),
> and is_dir() elements only. As of PHP 5.1.0: filemtime().
> [2] Use the normal file:// wrapper to stat compressed files.
>
> --
> Kim Andr Aker
> - kimandre@NOSPAMbetadome.com
> (remove NOSPAM to contact me directly)




Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Eric Layman

2007-02-01, 6:58 pm

Thanks!

btw, why is there a need for \r\n\r\n appended to the url?


"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:45c1cca6$0$48643$dbd43001@dr2.euro.net...
> Eric Layman schreef:
>
> It also states that you should look in the HTTP wrapper section of the
> appendix to see if it's supported by the stat() function. Like this
> function, filesize() only works on local files and doesn't support the
> HTTP protocol.
>
> If you want to check the size of a remote file, you could do something as
> follows:
>
> $fp = fsockopen('www.google.com', 80);
> fputs($fp, "HEAD / HTTP/1.0\r\n");
> fputs($fp, "Host: www.google.com\r\n\r\n");
>
> $size = 0;
> while (!feof($fp)) {
> $line = fgets($fp, 1024);
> if (preg_match('/content-length:\s*(\d+)/i', $line, $m)) {
> $size = $m[1];
> break;
> }
> }
> fclose($fp);
>
> print "Size of Google homepage HTML: $size bytes";
>
>
> JW




Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Janwillem Borleffs

2007-02-02, 7:58 am

Eric Layman schreef:
> Thanks!
>
> btw, why is there a need for \r\n\r\n appended to the url?
>


Yes, because it's used in a header context (Host), which should be ended
with CRLF characters.


JW
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com