| | |
fsockopen Jumping out of Loop
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I'm using fsockopen to access site URL's stored in a database and retrieve the meta information from the site. The loop for getting the URL's looks like this:
Next is a bit of parsing code, and then this:
The problem is, when fsockopen tries to access a site that is down or nonexistant, then it jumps out of the loop. I don't want it doing this. I want it to just update the database (setting status = 2 for the site) and then continue onto the next site. It doesn't even look like it's setting the status. It just exits out before the if statement.
How would I make fsockopen continue the loop? Or maybe an alternative to even using fsockopen?
PHP Syntax (Toggle Plain Text)
PHP Syntax (Toggle Plain Text)
$query_geturl = mysql_query("select * from sites"); while($geturl = @mysql_fetch_array($query_geturl, MYSQL_ASSOC)) {
Next is a bit of parsing code, and then this:
PHP Syntax (Toggle Plain Text)
$fp = fsockopen ($url['host'], ($url['port'] > 0 ? $url['port'] : 80), $errno, $errstr, $timeout); if (!$fp) { $query_status = mysql_query("update sites set status = '2' where url = '$usersite'"); } else { blah blah blah...
The problem is, when fsockopen tries to access a site that is down or nonexistant, then it jumps out of the loop. I don't want it doing this. I want it to just update the database (setting status = 2 for the site) and then continue onto the next site. It doesn't even look like it's setting the status. It just exits out before the if statement.
How would I make fsockopen continue the loop? Or maybe an alternative to even using fsockopen?
•
•
Join Date: Jul 2004
Posts: 234
Reputation:
Solved Threads: 8
I assume your full code look like this below.
[PHP] $query_geturl = mysql_query("select * from sites");
while($geturl = @mysql_fetch_array($query_geturl, MYSQL_ASSOC)) {
$fp = fsockopen ($url['host'], ($url['port'] > 0 ? $url['port'] : 80), $errno, $errstr, $timeout);
if (!$fp) {
$query_status = mysql_query("update sites set status = '2' where url = '$usersite'");
}
else {
//blah blah blah...
}
}
[/PHP]
Where does '$url' come from? '$url' means '$geturl'?
Also try like this below. Hope it helps.
[PHP] $query_geturl = mysql_query("select * from sites");
while($geturl = @mysql_fetch_array($query_geturl, MYSQL_ASSOC)) {
$fp = fsockopen ($geturl['host'], ($geturl['port'] > 0 ? $geturl['port'] : 80), $errno, $errstr, $timeout);
if (!$fp) {
$query_status = mysql_query("update sites set status = '2' where url = '$usersite'");
}
else {
//blah blah blah...
}
}
[/PHP]
[PHP] $query_geturl = mysql_query("select * from sites");
while($geturl = @mysql_fetch_array($query_geturl, MYSQL_ASSOC)) {
$fp = fsockopen ($url['host'], ($url['port'] > 0 ? $url['port'] : 80), $errno, $errstr, $timeout);
if (!$fp) {
$query_status = mysql_query("update sites set status = '2' where url = '$usersite'");
}
else {
//blah blah blah...
}
}
[/PHP]
Where does '$url' come from? '$url' means '$geturl'?
Also try like this below. Hope it helps.
[PHP] $query_geturl = mysql_query("select * from sites");
while($geturl = @mysql_fetch_array($query_geturl, MYSQL_ASSOC)) {
$fp = fsockopen ($geturl['host'], ($geturl['port'] > 0 ? $geturl['port'] : 80), $errno, $errstr, $timeout);
if (!$fp) {
$query_status = mysql_query("update sites set status = '2' where url = '$usersite'");
}
else {
//blah blah blah...
}
}
[/PHP]
![]() |
Similar Threads
- loop help (C++)
- breaking out of multiple loops (C)
- Loop...without the loop (Java)
Other Threads in the PHP Forum
- Previous Thread: Please Help: Unknown column
- Next Thread: CD Message Board
| Thread Tools | Search this Thread |
apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip javascript joomla limit link login mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop remote script search server sessions sms smtp soap source space sql strip_tags subversion support! survey syntax system table template tutorial undefined update upload url validator variable video virus web window.onbeforeunload=closeme; youtube





