472,791 Members | 1,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 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 2895
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,
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.