Re: [PHP] Test Links...
lol...if on linux... On Fri, 2003-09-26 at 12:35, Ray Hunter wrote: > Ive used curl to test stuff out with too...however, if on link i like to > use wget to test it out. You might not have that option but I have seen > others use fopen or file_get_contents. > > HTH, > > BigDog > > On Fri, 2003-09-26 at 10:15, Doug Coning wrote: > > Greetings All, > > > > I am creating a 'links' page and was wondering if there was a way in PHP > > to test the response of an outside link? I'm sure everyone here has > > clicked on a links page link and have a "No Page Found" error because no > > one is keeping the links uptodate. I was wondering if there was a way > > when a link was clicked to test the link first to see if it is still > > active. If it isn't active, I would like to remove the link from my > > database. > > > > Is there a command that tests the results of link? > > > > Thanks, > > > > Doug Coning > > American Web Studio > > http://www.americanwebstudio.com > > HTML / FLASH / PHP / MYSQL / FILEMAKER > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test Links...
Ive used curl to test stuff out with too...however, if on link i like to use wget to test it out. You might not have that option but I have seen others use fopen or file_get_contents. HTH, BigDog On Fri, 2003-09-26 at 10:15, Doug Coning wrote: > Greetings All, > > I am creating a 'links' page and was wondering if there was a way in PHP > to test the response of an outside link? I'm sure everyone here has > clicked on a links page link and have a "No Page Found" error because no > one is keeping the links uptodate. I was wondering if there was a way > when a link was clicked to test the link first to see if it is still > active. If it isn't active, I would like to remove the link from my > database. > > Is there a command that tests the results of link? > > Thanks, > > Doug Coning > American Web Studio > http://www.americanwebstudio.com > HTML / FLASH / PHP / MYSQL / FILEMAKER > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test Links...
Doug Coning said the following on 9/26/2003 12:15 PM>> Greetings All, I am creating a 'links' page and was wondering if there was a way in PHP to test the response of an outside link? I'm sure everyone here has clicked on a links page link and have a "No Page Found" error because no one is keeping the links uptodate. I was wondering if there was a way when a link was clicked to test the link first to see if it is still active. If it isn't active, I would like to remove the link from my database. Is there a command that tests the results of link? Thanks, Doug Coning Hi doug, try something like the function given here http://shiflett.org/dev/php_post.phps and check the returned headers .. there will be a field which will contain the status code (200 for successful / 404 for page not found etc). HTH R'twick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
DL Neil wrote: Beth, I noticed this reference to "$http_response_header" and straightaway quizzed the manual, only to find that the only references to it (eg file open) lead nowhere. Have gone through a few other pages, looking to see if I might happen upon some detail, but failed. Sadly you don't refer to it in the code snippet provided (below). Any code I've attempted blindly has failed/reported errors. Please point me in the right direction (otherwise I guess it'll be time to download the new v4.3.0-RC and risk the bleeding edge - which according to the manual does something different anyway...) Yeah, it's not mentioned anywhere else, I just completely guessed at what to do with this and got lucky on the first attempt, but if you do a ... print_r($http_response_header); ?> ... you get tons of junk like: Array ( [0] => HTTP/1.1 200 OK [1] => Date: Mon, 02 Dec 2002 17:54:47 GMT [2] => Server: Apache/1.3.27 (Unix) PHP/4.2.3 mod_perl/1.27 mod_gzip/1.3.19.1a [3] => Cache-Control: max-age=900, public, must-revalidate, max-age=900 [4] => Expires: Mon, 02 Dec 2002 18:09:47 GMT [5] => Last-Modified: Mon, 02 Dec 2002 17:51:56 GMT [6] => ETag: "28de7-cfa4-3deb9dbc" [7] => Accept-Ranges: bytes [8] => Content-Length: 53156 [9] => Connection: close [10] => Content-Type: text/html; charset=iso-8859-1 ) When I first programmed the little function for Rob, I used it to check for a 200 status, but it turns out that fopen completely fails UNLESS it gets that 200, so it wasn't necessary. Beth Gore -- http://bethanoia.dyndns.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Rob/Beth, The code should also consider: 1 updating the db if the link is 'valid', ie if previously it had been 'down'! 2 putting an @ to prevent any errors causing a hard-stop at the fopen line 3 that the url/database must contain protocol information, ie http://www.nytimes.com not www.nytimes.com. Thanks for the discussion, =dn > Rob Packer wrote: > > >Okay, I'm confused... file, fopen, and fsockopen seem to say not found on > >alot valid URLs... does this look to be correct usage? > >$url = $row[0]; // just get the url from the db > >$fp = implode ('', file ($url)); > > if (!$fp) {echo "Unable to access file"; } > > else { fclose($fp); echo "The link is working!"; } > > > >It seems I always get this warning... > > > >Warning: Supplied argument is not a valid File-Handle resource in > >/web/home/nrc.net/www/robert/links4.php on line 11 > > > >If someone can tell me what I'm doing wrong, I'd appreciate it. > > > >Thanks, > >Robert > > > > > > > > > > > When fopen successfully opens a file it populates an array > $http_response_header, which you can examine to see if the link works or > not - I don't believe you can actually get the file itself, but since > that's not what we're after that's not a problem! > > Having said that, fopen produces a very annoying error if it doesn't > find the page, but I found the following works: > > > $SQL = "SELECT linkurl, linkID FROM links"; > $result = mysql_query($SQL); > > while($linkdata = mysql_fetch_array($result)){ > > $fp = fopen($linkdata['linkurl'],"r"); > if($fp) > { > echo "".$linkdata['linkurl']." is still valid."; > > }else{ > > echo "".$linkdata['linkurl']." is invalid. Updating > database... "; > > $SQL = "UPDATE links SET status = 0 WHERE linkID = > '".$linkdata['linkID']."'"; > $result2 = mysql_query($SQL); > if($result2) > { > echo "Database updated"; > } > } > > } > ?> > > Rather than deleting the link, it's probably better to set a flag to > show it was invalid last time you checked, but check it again next time. > Or you could keep a count of the number of failed attempts, and delete > if it goes beyond 3 or so. > > Not sure how to supress the warning message that PHP automatically does > when you haven't got a valid URL though. > > Hope this works for you! > > Beth Gore > -- > http://bethanoia.dyndns.org > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Beth, > When fopen successfully opens a file it populates an array > $http_response_header, which you can examine to see if the link works or > not - I don't believe you can actually get the file itself, but since > that's not what we're after that's not a problem! I noticed this reference to "$http_response_header" and straightaway quizzed the manual, only to find that the only references to it (eg file open) lead nowhere. Have gone through a few other pages, looking to see if I might happen upon some detail, but failed. Sadly you don't refer to it in the code snippet provided (below). Any code I've attempted blindly has failed/reported errors. Please point me in the right direction (otherwise I guess it'll be time to download the new v4.3.0-RC and risk the bleeding edge - which according to the manual does something different anyway...) =dn > Having said that, fopen produces a very annoying error if it doesn't > find the page, but I found the following works: > > > $SQL = "SELECT linkurl, linkID FROM links"; > $result = mysql_query($SQL); > > while($linkdata = mysql_fetch_array($result)){ > > $fp = fopen($linkdata['linkurl'],"r"); > if($fp) > { > echo "".$linkdata['linkurl']." is still valid."; > > }else{ > > echo "".$linkdata['linkurl']." is invalid. Updating > database... "; > > $SQL = "UPDATE links SET status = 0 WHERE linkID = > '".$linkdata['linkID']."'"; > $result2 = mysql_query($SQL); > if($result2) > { > echo "Database updated"; > } > } > > } > ?> > > Rather than deleting the link, it's probably better to set a flag to > show it was invalid last time you checked, but check it again next time. > Or you could keep a count of the number of failed attempts, and delete > if it goes beyond 3 or so. > > Not sure how to supress the warning message that PHP automatically does > when you haven't got a valid URL though. > > Hope this works for you! > > Beth Gore > -- > http://bethanoia.dyndns.org > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Yes I did. Thanks. - Original Message - From: "Jason Wong" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, December 01, 2002 2:30 AM Subject: Re: [PHP] Test links? > On Sunday 01 December 2002 15:33, Hugh Danaher wrote: > > Not sure how to supress the warning message that PHP automatically does > > when you haven't got a valid URL though. > > Error reporting options can be set in php.ini or by using ini_set(). > > > should be able to surpress errors by adding an * before the result variable > > > > *$fp = fopen($linkdata['linkurl'],"r"); > > I think you mean '@': > > $fp = @fopen($linkdata['linkurl'],"r"); > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > > /* > Blessed is he who expects no gratitude, for he shall not be disappointed. > -- W.C. Bennett > */ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
On Sunday 01 December 2002 15:33, Hugh Danaher wrote: > Not sure how to supress the warning message that PHP automatically does > when you haven't got a valid URL though. Error reporting options can be set in php.ini or by using ini_set(). > should be able to surpress errors by adding an * before the result variable > > *$fp = fopen($linkdata['linkurl'],"r"); I think you mean '@': $fp = @fopen($linkdata['linkurl'],"r"); -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Blessed is he who expects no gratitude, for he shall not be disappointed. -- W.C. Bennett */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Not sure how to supress the warning message that PHP automatically does when you haven't got a valid URL though. should be able to surpress errors by adding an * before the result variable *$fp = fopen($linkdata['linkurl'],"r"); Hope this helps--or even works for this particular problem. Hugh - Original Message - From: "Beth Gore" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, November 30, 2002 11:02 AM Subject: Re: [PHP] Test links? > Rob Packer wrote: > > >Okay, I'm confused... file, fopen, and fsockopen seem to say not found on > >alot valid URLs... does this look to be correct usage? > >$url = $row[0]; // just get the url from the db > >$fp = implode ('', file ($url)); > > if (!$fp) {echo "Unable to access file"; } > > else { fclose($fp); echo "The link is working!"; } > > > >It seems I always get this warning... > > > >Warning: Supplied argument is not a valid File-Handle resource in > >/web/home/nrc.net/www/robert/links4.php on line 11 > > > >If someone can tell me what I'm doing wrong, I'd appreciate it. > > > >Thanks, > >Robert > > > > > > > > > > > When fopen successfully opens a file it populates an array > $http_response_header, which you can examine to see if the link works or > not - I don't believe you can actually get the file itself, but since > that's not what we're after that's not a problem! > > Having said that, fopen produces a very annoying error if it doesn't > find the page, but I found the following works: > > > $SQL = "SELECT linkurl, linkID FROM links"; > $result = mysql_query($SQL); > > while($linkdata = mysql_fetch_array($result)){ > > $fp = fopen($linkdata['linkurl'],"r"); > if($fp) > { > echo "".$linkdata['linkurl']." is still valid."; > > }else{ > > echo "".$linkdata['linkurl']." is invalid. Updating > database... "; > > $SQL = "UPDATE links SET status = 0 WHERE linkID = > '".$linkdata['linkID']."'"; > $result2 = mysql_query($SQL); > if($result2) > { > echo "Database updated"; > } > } > > } > ?> > > Rather than deleting the link, it's probably better to set a flag to > show it was invalid last time you checked, but check it again next time. > Or you could keep a count of the number of failed attempts, and delete > if it goes beyond 3 or so. > > Not sure how to supress the warning message that PHP automatically does > when you haven't got a valid URL though. > > Hope this works for you! > > Beth Gore > -- > http://bethanoia.dyndns.org > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Thanks for the help and suggestions everybody! I think some of my problems stemmed from the affiliate links being redirected and PHP saw that as dead(so to speak)... but I think I got it now. I made another column in the database to note a redirection for ones that the url fails but the $url[host] passes. Robert Packer "Chris Hewitt" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Rob Packer wrote: > > >Okay, I'm confused... file, fopen, and fsockopen seem to say not found on > >alot valid URLs... does this look to be correct usage? > >$url = $row[0]; // just get the url from the db > >$fp = implode ('', file ($url)); > > if (!$fp) {echo "Unable to access file"; } > > else { fclose($fp); echo "The link is working!"; } > > > >It seems I always get this warning... > > > >Warning: Supplied argument is not a valid File-Handle resource in > >/web/home/nrc.net/www/robert/links4.php on line 11 > > > I think you have assigned $fp to be the imploded string, not a file > pointer. Thus fclose($fp) would generate an error. Given this, I'm not > sure what "if (!$fp)" would mean. > > HTH > Chris > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Rob Packer wrote: Okay, I'm confused... file, fopen, and fsockopen seem to say not found on alot valid URLs... does this look to be correct usage? $url = $row[0]; // just get the url from the db $fp = implode ('', file ($url)); if (!$fp) {echo "Unable to access file"; } else { fclose($fp); echo "The link is working!"; } It seems I always get this warning... Warning: Supplied argument is not a valid File-Handle resource in /web/home/nrc.net/www/robert/links4.php on line 11 I think you have assigned $fp to be the imploded string, not a file pointer. Thus fclose($fp) would generate an error. Given this, I'm not sure what "if (!$fp)" would mean. HTH Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Rob Packer wrote: Okay, I'm confused... file, fopen, and fsockopen seem to say not found on alot valid URLs... does this look to be correct usage? $url = $row[0]; // just get the url from the db $fp = implode ('', file ($url)); if (!$fp) {echo "Unable to access file"; } else { fclose($fp); echo "The link is working!"; } It seems I always get this warning... Warning: Supplied argument is not a valid File-Handle resource in /web/home/nrc.net/www/robert/links4.php on line 11 If someone can tell me what I'm doing wrong, I'd appreciate it. Thanks, Robert When fopen successfully opens a file it populates an array $http_response_header, which you can examine to see if the link works or not - I don't believe you can actually get the file itself, but since that's not what we're after that's not a problem! Having said that, fopen produces a very annoying error if it doesn't find the page, but I found the following works: $SQL = "SELECT linkurl, linkID FROM links"; $result = mysql_query($SQL); while($linkdata = mysql_fetch_array($result)){ $fp = fopen($linkdata['linkurl'],"r"); if($fp) { echo "".$linkdata['linkurl']." is still valid."; }else{ echo "".$linkdata['linkurl']." is invalid. Updating database... "; $SQL = "UPDATE links SET status = 0 WHERE linkID = '".$linkdata['linkID']."'"; $result2 = mysql_query($SQL); if($result2) { echo "Database updated"; } } } ?> Rather than deleting the link, it's probably better to set a flag to show it was invalid last time you checked, but check it again next time. Or you could keep a count of the number of failed attempts, and delete if it goes beyond 3 or so. Not sure how to supress the warning message that PHP automatically does when you haven't got a valid URL though. Hope this works for you! Beth Gore -- http://bethanoia.dyndns.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
On Sunday 01 December 2002 02:06, Rob Packer wrote: > Okay, I'm confused... file, fopen, and fsockopen seem to say not found on > alot valid URLs... does this look to be correct usage? > $url = $row[0]; // just get the url from the db > $fp = implode ('', file ($url)); > if (!$fp) {echo "Unable to access file"; } > else { fclose($fp); echo "The link is working!"; } > > It seems I always get this warning... > > Warning: Supplied argument is not a valid File-Handle resource in > /web/home/nrc.net/www/robert/links4.php on line 11 Which is line 11? In the above, if link was valid and returned something then $fp would be a string containing the HTML source of the $url. If the link was invalid (I'm not sure what exactly PHP would regard as an invalid link) then PHP would output a warning/error message (make sure you have error reporting set to an appropriately high level). file() implicitly opens and closes the file for you so no need for fclose(). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* The rhino is a homely beast, For human eyes he's not a feast. Farewell, farewell, you old rhinoceros, I'll stare at something less prepoceros. -- Ogden Nash */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Okay, I'm confused... file, fopen, and fsockopen seem to say not found on alot valid URLs... does this look to be correct usage? $url = $row[0]; // just get the url from the db $fp = implode ('', file ($url)); if (!$fp) {echo "Unable to access file"; } else { fclose($fp); echo "The link is working!"; } It seems I always get this warning... Warning: Supplied argument is not a valid File-Handle resource in /web/home/nrc.net/www/robert/links4.php on line 11 If someone can tell me what I'm doing wrong, I'd appreciate it. Thanks, Robert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
On Saturday 30 November 2002 21:40, Rob Packer wrote: > Well, the reason I didn't do that at first was that I could have done any > of the methods that I've tried incorrectly, which is why I figured I'd ask > what works and then focus on that method... but, I've tried to ping them, > use fopen, and use fsocketopen... but nothing says that I've used any of > them the way I should have :) I also tried to use the scripts that I found > at hotscripts.com but I always seem to get inconsistent results and it must > be accurate. Investigate the use of file(). It should be the most reliable indicator of whether or not a link is valid. Using ping on it's own doesn't really help much. A server may be configured to ignore ping requests. And even if a server responds to a ping request it doesn't mean the webserver is up and running. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Nothing astonishes men so much as common sense and plain dealing. -- Ralph Waldo Emerson */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
Well, the reason I didn't do that at first was that I could have done any of the methods that I've tried incorrectly, which is why I figured I'd ask what works and then focus on that method... but, I've tried to ping them, use fopen, and use fsocketopen... but nothing says that I've used any of them the way I should have :) I also tried to use the scripts that I found at hotscripts.com but I always seem to get inconsistent results and it must be accurate. "Jason Wong" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Saturday 30 November 2002 06:53, Rob Packer wrote: > > First, I'd like to say that I'm not asking for anyone to write a script... > > how would I go about checking a MySQL database of links to see if any are > > down? > > > > I've had some varying results with all the methods I've tried, so would > > like to see if anyone has a proven method for doing this. > > Why don't you briefly summarise what methods you have tried? That way people > won't reply with methods that you already know of. > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > > /* > Between grand theft and a legal fee, there only stands a law degree. > */ > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
On Saturday 30 November 2002 06:53, Rob Packer wrote: > First, I'd like to say that I'm not asking for anyone to write a script... > how would I go about checking a MySQL database of links to see if any are > down? > > I've had some varying results with all the methods I've tried, so would > like to see if anyone has a proven method for doing this. Why don't you briefly summarise what methods you have tried? That way people won't reply with methods that you already know of. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Between grand theft and a legal fee, there only stands a law degree. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Test links?
fopen each link and see if it returns true or false (false meaning its down) Jason Reid [EMAIL PROTECTED] -- AC Host Canada www.achost.ca - Original Message - From: "Rob Packer" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 29, 2002 3:53 PM Subject: [PHP] Test links? > First, I'd like to say that I'm not asking for anyone to write a script... > how would I go about checking a MySQL database of links to see if any are > down? > > I've had some varying results with all the methods I've tried, so would like > to see if anyone has a proven method for doing this. > > Thanks, > Robert > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php