09-17-2007
|
#1 (permalink)
|
|
Sheep Worrier
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,066
|
Bizarre Cron Error
Heya peeps! As many of you know, I use a lot of crons to make the site appear dynamic but greatly reduce the number of queries that are thrown around. This may seem a bit of a cheat, but when they are run every 30-60 seconds nobody ever notices.  Anyway, when I upgraded the server I seem to have developed a bit of a problem with the script that controls the image gallery thumbs on the main page. Here's the code:
PHP Code:
$dbcnx = mysql_connect("localhost", "forumusername", "forumpassword");
mysql_select_db("database_forums", $dbcnx);
$numberOfEntries = getNumRows("photopost_photos", "id > 0");
$desirednumber = $numberofentries - 12;
$entries = getRows("photopost_photos", "id > $desirednumber ORDER BY date DESC");
$flash = "http://forums.biorust.com/photopost/images/mm-fla.gif";
$picture = $entries[0]["bigimage"];
$category = $entries[0]["cat"];
$id0 = $entries[0]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl0 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl0 = $flash; }
$author0 = $entries[0]["user"];
$title0 = $entries[0]["title"];
$title0 = stripslashes($title0);
$length = strlen($title0);
if($length > 32) { $title0 = substr($title0, 0, 30)."..."; }
$picture = $entries[1]["bigimage"];
$category = $entries[1]["cat"];
$id1 = $entries[1]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl1 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl1 = $flash; }
$author1 = $entries[1]["user"];
$title1 = $entries[1]["title"];
$title1 = stripslashes($title1);
$length = strlen($title1);
if($length > 32) { $title1 = substr($title1, 0, 30)."..."; }
$picture = $entries[2]["bigimage"];
$category = $entries[2]["cat"];
$id2 = $entries[2]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl2 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl2 = $flash; }
$author2 = $entries[2]["user"];
$title2 = $entries[2]["title"];
$title2 = stripslashes($title2);
$length = strlen($title2);
if($length > 32) { $title2 = substr($title2, 0, 30)."..."; }
$picture = $entries[3]["bigimage"];
$category = $entries[3]["cat"];
$id3 = $entries[3]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl3 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl3 = $flash; }
$author3 = $entries[3]["user"];
$title3 = $entries[3]["title"];
$title3 = stripslashes($title3);
$length = strlen($title3);
if($length > 32) { $title3 = substr($title3, 0, 30)."..."; }
$picture = $entries[4]["bigimage"];
$category = $entries[4]["cat"];
$id4 = $entries[4]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl4 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl4 = $flash; }
$author4 = $entries[4]["user"];
$title4 = $entries[4]["title"];
$title4 = stripslashes($title4);
$length = strlen($title4);
if($length > 32) { $title4 = substr($title4, 0, 30)."..."; }
$picture = $entries[5]["bigimage"];
$category = $entries[5]["cat"];
$id5 = $entries[5]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl5 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl5 = $flash; }
$author5 = $entries[5]["user"];
$title5 = $entries[5]["title"];
$title5 = stripslashes($title5);
$length = strlen($title5);
if($length > 32) { $title5 = substr($title5, 0, 30)."..."; }
$picture = $entries[6]["bigimage"];
$category = $entries[6]["cat"];
$id6 = $entries[6]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl6 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl6 = $flash; }
$author6 = $entries[6]["user"];
$title6 = $entries[6]["title"];
$title6 = stripslashes($title6);
$length = strlen($title6);
if($length > 32) { $title6 = substr($title6, 0, 30)."..."; }
$picture = $entries[7]["bigimage"];
$category = $entries[7]["cat"];
$id7 = $entries[7]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl7 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl7 = $flash; }
$author7 = $entries[7]["user"];
$title7 = $entries[7]["title"];
$title7 = stripslashes($title7);
$length = strlen($title7);
if($length > 32) { $title7 = substr($title7, 0, 30)."..."; }
$picture = $entries[8]["bigimage"];
$category = $entries[8]["cat"];
$id8 = $entries[8]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl8 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl8 = $flash; }
$author8 = $entries[8]["user"];
$title8 = $entries[8]["title"];
$title8 = stripslashes($title8);
$length = strlen($title8);
if($length > 32) { $title8 = substr($title8, 0, 30)."..."; }
$picture = $entries[9]["bigimage"];
$category = $entries[9]["cat"];
$id9 = $entries[9]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl9 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl9 = $flash; }
$author9 = $entries[9]["user"];
$title9 = $entries[9]["title"];
$title9 = stripslashes($title9);
$length = strlen($title9);
if($length > 32) { $title9 = substr($title9, 0, 30)."..."; }
$picture = $entries[10]["bigimage"];
$category = $entries[10]["cat"];
$id10 = $entries[10]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl10 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl10 = $flash; }
$author10 = $entries[10]["user"];
$title10 = $entries[10]["title"];
$title10 = stripslashes($title10);
$length = strlen($title10);
if($length > 32) { $title10 = substr($title10, 0, 30)."..."; }
$picture = $entries[11]["bigimage"];
$category = $entries[11]["cat"];
$id11 = $entries[11]["id"];
if (!preg_match("/.swf/i", $picture)) { $picurl11 = "http://forums.biorust.com/photopost/data/$category/thumbs/$picture"; } else {$picurl11 = $flash; }
$author11 = $entries[11]["user"];
$title11 = $entries[11]["title"];
$title11 = stripslashes($title11);
$length = strlen($title11);
if($length > 32) { $title11 = substr($title11, 0, 30)."..."; }
$fp3 = fopen("cron-newestsubmissions.txt","w");
if(!$fp3) {
print "error! The file could not be opened";
exit;
}
$stringtowrite3='<div align="center"><table border="0" width="100%" cellpadding="5"><tr>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id0 . '"><img style="border: 1px solid #66665F;" alt="sub0" title="'.$title0.', by '.$author0.'" src="' . $picurl0 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id1 . '"><img style="border: 1px solid #66665F;" alt="sub1" title="'.$title1.', by '.$author1.'" src="' . $picurl1 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id2 . '"><img style="border: 1px solid #66665F;" alt="sub2" title="'.$title2.', by '.$author2.'" src="' . $picurl2 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id3 . '"><img style="border: 1px solid #66665F;" alt="sub3" title="'.$title3.', by '.$author3.'" src="' . $picurl3 . '"></a></td>';
$stringtowrite3.='</tr><tr>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id4 . '"><img style="border: 1px solid #66665F;" alt="sub4" title="'.$title4.', by '.$author4.'" src="' . $picurl4 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id5 . '"><img style="border: 1px solid #66665F;" alt="sub5" title="'.$title5.', by '.$author5.'" src="' . $picurl5 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id6 . '"><img style="border: 1px solid #66665F;" alt="sub6" title="'.$title6.', by '.$author6.'" src="' . $picurl6 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id7 . '"><img style="border: 1px solid #66665F;" alt="sub7" title="'.$title7.', by '.$author7.'" src="' . $picurl7 . '"></a></td>';
$stringtowrite3.='</tr><tr>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id8 . '"><img style="border: 1px solid #66665F;" alt="sub8" title="'.$title8.', by '.$author8.'" src="' . $picurl8 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id9 . '"><img style="border: 1px solid #66665F;" alt="sub9" title="'.$title9.', by '.$author9.'" src="' . $picurl9 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id10 . '"><img style="border: 1px solid #66665F;" alt="sub10" title="'.$title10.', by '.$author10.'" src="' . $picurl10 . '"></a></td>';
$stringtowrite3.='<td align="center"><a href="http://forums.biorust.com/photopost/showphoto.php?photo=' . $id11 . '"><img style="border: 1px solid #66665F;" alt="sub11" title="'.$title11.', by '.$author11.'" src="' . $picurl11 . '"></a></td>';
$stringtowrite3.='</tr></table></div>';
fwrite($fp3, $stringtowrite3);
fclose($fp3);
The error that its chucking up is a 500 server config error... but its never done anything like that before, and worked perfect on the old server. All files are CHMODed correctly. Any ideas?
__________________
|
|
|
09-18-2007
|
#2 (permalink)
|
|
Moderator
Join Date: Jul 2004
Location: Quebec City, Canada
Posts: 50
|
PHP Code:
$numberOfEntries = getNumRows("photopost_photos", "id > 0"); $desirednumber = $numberofentries - 12;
Gotcha, PHP is a case-sensitive language
$numberOfEntries and $numberofentries are totally different variables. This little mistake lead to catastrophic consequences later in the script, namely to what I believe is a simple out-of-memory error during the execution of getRows(). Anyway, I hope this fixes it.
|
|
|
09-18-2007
|
#3 (permalink)
|
|
PHP Lover
Join Date: May 2007
Location: Zug, Switzerland
Posts: 84
|
Quote:
Originally Posted by The Eagle
PHP Code:
$numberOfEntries = getNumRows("photopost_photos", "id > 0");
$desirednumber = $numberofentries - 12;
Gotcha, PHP is a case-sensitive language
$numberOfEntries and $numberofentries are totally different variables. This little mistake lead to catastrophic consequences later in the script, namely to what I believe is a simple out-of-memory error during the execution of getRows(). Anyway, I hope this fixes it.
|
Yeah that should fix it, if not send me your phperror log and I'll tell you what the problem is  Btw with PHP, 500 error messages can also be caused by something silly like htaccess files, although that usually applies to a shared hosting environment.
One other tip that I can share with you is that when you are naming variables, instead of using upper and lowercase names like:
PHP Code:
$numberOfEntries
try using
PHP Code:
$number_of_entries
it is slightly longer, but at least you don't have to worry about typing all the capital letters in exactly the right places.
|
|
|
09-18-2007
|
#4 (permalink)
|
|
Sheep Worrier
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,066
|
Many thanks guys! You both had it right - it was the variable capitalisation. W00t - its great to have a working server once more! 
__________________
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 07:55 AM. Content Relevant URLs by vBSEO 3.2.0
|