473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

fopen/fsockopen question

Dear All,

I want to write a simple PHP code to verify whether a given list of
URLs is broken or not. The URLs given have various formats, for example,

http://www.afro.com/history/history.html
http://www.worldhistorycompass.com/index.htm
http://www.afup.org/article.php3?id_article=242

fsockopen(...) only accepts target format (like www.yahoo.com etc), so I
simply choose fopen (url,'r') to do the test.

This method seems working well for majority of URLs I have. However,
when the following site seems causing problem,

$site = fopen("http://www.marketingpower.com/live/topics12.php",'r');

my browser seems working very hard on this link and after a long time,
the browser stops (not continuing on the next command. I am using
netscape on linux).

Initially I thought probably fopen doesn't like http://xxxx/xxx.php type
of format, however, links like:

http://www.afup.org/article.php3?id_article=242

works just fine.

So I am confused. Can anybody give me a hint on this?

Thanks.

Jul 17 '05 #1
5 2948
Shaoyong Wang wrote:
Dear All,

I want to write a simple PHP code to verify whether a given list of
URLs is broken or not. The URLs given have various formats, for example,

http://www.afro.com/history/history.html
http://www.worldhistorycompass.com/index.htm
http://www.afup.org/article.php3?id_article=242

fsockopen(...) only accepts target format (like www.yahoo.com etc), so I
simply choose fopen (url,'r') to do the test.

This method seems working well for majority of URLs I have. However,
when the following site seems causing problem,

$site = fopen("http://www.marketingpower.com/live/topics12.php",'r');

my browser seems working very hard on this link and after a long time,
the browser stops (not continuing on the next command. I am using
netscape on linux).

Initially I thought probably fopen doesn't like http://xxxx/xxx.php type
of format, however, links like:

http://www.afup.org/article.php3?id_article=242

works just fine.

So I am confused. Can anybody give me a hint on this?

Thanks.


I've tried to use nc to open the site you mentioned. It seems it does a
whole lot of redirecting and setting cookies. Might be that's what's
giving the URL wrapper trouble opening the page properly.

If that's the case, you will have no other choice than to write your own
HTTP request handler, which handles redirects and cookies. Which isn't
too hard, but it's a lot of work :).

-Rico
Jul 17 '05 #2
Thanks.

This link seems the only problematic one so far. I can just skip this one.
Notice fopen can't stop at this link, even I set max_execution_time in
php.ini, no idea.
I am using PHP 4.2.2

Jul 17 '05 #3
On Thu, 27 May 2004 13:11:59 +0200, Rico Huijbers
<E.************@REMOVEstudent.tue.nl> wrote:
Shaoyong Wang wrote:
Dear All,

I want to write a simple PHP code to verify whether a given list of
URLs is broken or not. The URLs given have various formats, for example,

http://www.afro.com/history/history.html
http://www.worldhistorycompass.com/index.htm
http://www.afup.org/article.php3?id_article=242

fsockopen(...) only accepts target format (like www.yahoo.com etc), so I
simply choose fopen (url,'r') to do the test.

This method seems working well for majority of URLs I have. However,
when the following site seems causing problem,

$site = fopen("http://www.marketingpower.com/live/topics12.php",'r');

my browser seems working very hard on this link and after a long time,
the browser stops (not continuing on the next command. I am using
netscape on linux).

Initially I thought probably fopen doesn't like http://xxxx/xxx.php type
of format, however, links like:

http://www.afup.org/article.php3?id_article=242

works just fine.

So I am confused. Can anybody give me a hint on this?

Thanks.


I've tried to use nc to open the site you mentioned. It seems it does a
whole lot of redirecting and setting cookies. Might be that's what's
giving the URL wrapper trouble opening the page properly.

If that's the case, you will have no other choice than to write your own
HTTP request handler, which handles redirects and cookies. Which isn't
too hard, but it's a lot of work :).


couldn't you just do something like this?:

$hostname = preg_replace('/http:\/\/([^\/]*).*/','$1',$url);
$conn_id = fsockopen('tcp://' . gethostbyname($hostname), 80,
$errno, $errstr);
fputs($conn_id,"GET $url HTTP/1.1\r\nHost: $hostname\r\n\r\n");

where $url is the url in question, and then where you do whatever you
would normally do?
Jul 17 '05 #4
Shaoyong Wang <wa*****@cis.ohio-state.edu> wrote in message news:<c9**********@news.cis.ohio-state.edu>...
Thanks.

This link seems the only problematic one so far. I can just skip this one.
Notice fopen can't stop at this link, even I set max_execution_time in
php.ini, no idea.
I am using PHP 4.2.2


1. If possible, use cURL functions instead. It is much handy
2. Check the user_agent setting of your ini file. Some sites may
lock weird/unknown user agents.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
Shaoyong Wang wrote:
Dear All,

I want to write a simple PHP code to verify whether a given list of
URLs is broken or not. The URLs given have various formats, for example,

http://www.afro.com/history/history.html
http://www.worldhistorycompass.com/index.htm
http://www.afup.org/article.php3?id_article=242

fsockopen(...) only accepts target format (like www.yahoo.com etc), so I
simply choose fopen (url,'r') to do the test.

This method seems working well for majority of URLs I have. However,
when the following site seems causing problem,

$site = fopen("http://www.marketingpower.com/live/topics12.php",'r');

my browser seems working very hard on this link and after a long time,
the browser stops (not continuing on the next command. I am using
netscape on linux).

Initially I thought probably fopen doesn't like http://xxxx/xxx.php type
of format, however, links like:

http://www.afup.org/article.php3?id_article=242

works just fine.

So I am confused. Can anybody give me a hint on this?

Thanks.


just use fopen

what you have to decide on are how many conditions do you have to deal with.

1) success!
2) a 404 response (file not found)
3) connection refused (port not listening)
4) timeout (server is down or not resolvable)

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: theouimets | last post by:
Is there a limit to how long a URL can be with fopen? I have a very long URL as there are lots of things to be passed some variables and some XML. It seems to get to a certain point and then...
3
by: Ming | last post by:
When I use fopen on the URL: fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r") I would get the following error message: -----------Error Message------------ Warning: fopen():...
12
by: Bill | last post by:
For my personal use I am accessing a railway timetable page, parsing its contents and then sending brief relevant information as the subject line of an email to be read on a mobile phone. The...
8
by: ARGENTINA | last post by:
I ve been trying php script sent by rchaplin and all goes ok automatically appears a new file copied after script execution but it appears a messaje like next one: Warning: fopen(): URL...
2
by: Loopy | last post by:
I'm trying to write a script that will connect to an external site so that I can get access referer information in a database on another one of my sites. I got errors, so I tried to write a script...
5
by: meenasamy | last post by:
Hi all i have used a script that i downloaded and uses the fopen($url,'r'); function to access a url to retrieve data and i get this error Fatal error: fopen(): Unable to find the wrapper...
4
by: peter.hrdy | last post by:
Hi guys. i have big problem with using fopen, fsockopen or curl. if i tried to use it on remote site it doesn't works. i've readed to much posts but didn't found anything helpfulll. fopen just...
4
by: Aetherweb | last post by:
On my site I'm reading content from a URL with a statement like this: if ($fp = @fopen("http://www.mydom.com/test.aspx", "r")) { do something } else { do something else }
3
by: jeddiki | last post by:
Out of these, which one do you use most and why ? fsockopen, curl, fopen, file_get_contents,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.