file ('http://'); not working

Mirage

Administrator
Staff member
V.I.P.
#1
Hopefully this is simple. I am trying to pull an outside webpage into an array in PHP in order to take values from it..

I have tried this as described on php.net:

PHP:
$lines = file('http://www.example.com/');
The page just stalls and eventually doesn't do anything. I have a line "done" set to be echoed at the end of the page which also does not appear when I add the above code.

I'm running this on a Windows server with IIS 6.0.

The page I am getting this info from is: http://us2.php.net/manual/en/function.file.php

The tip on PHP.net says:

Tip: You can use a URL as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and Appendix M for a list of supported URL protocols.
I have enabled "allow_url_fopen" as well.

I can load local files, but just not remote files. Any ideas?

Thanks! :)
 

Mr_Snipes

Registered Member
#4
No, that is the only place you can enable it. Just checking to make sure that you did that one, just in case you had not done that yet.
 

Mirage

Administrator
Staff member
V.I.P.
#6
It didn't matter because it didn't create the array in the first place due to "file" not working.

I have since created an alternative function to do this, but it still bugs me that I can't get the built in function working.
 

Spinlock

Registered Member
#7
Okay... let me put it this way.
Does the function work if you just point it to a webpage with EXACTLY one element in it?
Have you tried echoing the content of $lines directly after that line?
 
Last edited:

myessence

Registered Member
#8
Hopefully this is simple. I am trying to pull an outside webpage into an array in PHP in order to take values from it..

The page just stalls and eventually doesn't do anything. I have a line "done" set to be echoed at the end of the page which also does not appear when I add the above code.

I've had this happening to me with a few websites.

Turned out I need to set a user_agent on php.ini. Preferably, to a popular one (eg: IE6, Firefox 1.5.x, etc)

A few examples :

// user_agent="Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)"
// alternatives:
// "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
// "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"
// "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"
// "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"

In another case, increasing default_socket_timeout to 600 helps, especially with those REALLY slow websites :)

Hope it helps.