Topic: PHP: Seeing All Errors in Code

hi all.  newb programmer here trying to make a bittorrent indexer plugin for punbb.  i have all the easy stuff working and now i'm trying to tackle the object that scrapes other trackers.  my module isn't producing any errors in my servers error scripts log but i know darn well i''ve made a couple of mistakes.  so how do you guys see all the errors in your code?  do you just 'echo' variables everywhere to see what's going on?  thanks for any tips.

for amusement purposes here's some code.  i know i've made mistakes in punscrape.  probably a bunch of 'em...

<?php

/*

  This file isn't part of PunBB.  This file is part of puntracker
  a bittorrent tracker module for PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

*/

// let's keep tracker within punbb
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';

// the scrape object
class punscrape
{
    function do_scrape()
    {

    global $db;
    
// let's check if the torrent(s) need to be scraped.
$table = $db->prefix.'puntracker';
$result = $db->query("SELECT * FROM $table 
WHERE TIMEDIFF(NOW(), $table.last_scrape) >= '0000-00-00 01:30:00'");

while ($row = $db->fetch_assoc($result)) {

// if query returns a row, scrape url
    if (isset($row['announce'])) {

$announce_url=$row['announce'];
$hash=$row['hash'];

// let's transform the announce url to a specific torrent scrape
$scrape_url = preg_replace ( '<announce.*>', 'scrape?hash_id='.$hash, $announce_url); 

// create a new cURL resource
// we may need to set CURLOPT_CONNECTTIMEOUT
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $scrape_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  // to return text
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL text and set $scrape_result
$scrape_result = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

// let's extract complete (seeds), downloaded and incomplete (peers).
preg_match("<completei\d*>", $scrape_result, $matches_complete);
preg_match("<downloadedi\d*>", $scrape_result, $matches_downloaded);
preg_match("<incompletei\d*>", $scrape_result, $matches_incomplete);

// get the substring of only numbers.
// i don't think i an do this on an array
$complete = substr($matches_complete, 9);
$downloads = substr($matches_downloaded, 11);
$incomplete = substr($matches_incomplete, 11);

// if scrape returns text update mysql
// not secure.  we need to check better prior to update
if (isset($complete)) {

//  update mysql.  *CHECK THIS IN PHPMYADMIN TO MAKE SURE I'M NOT RETARdED*
$sql = "UPDATE $table";
$sql .= " ( complete, downloads, incomplete, last_scrape ) VALUES ";
$sql .= " ( '$complete', '$downloads', '$incomplete', NOW())";
$sql .= " WHERE '$hash' = hash";

} } }

}}

$updatedb = new punscrape;
$updatedb->do_scrape();

// if scrape fails for 3 days DELETE
// this query runs everytime the page is viewed.  not efficient.
$table = $db->prefix.'puntracker';
$query = "DELETE FROM $table WHERE $table.last_scrape <= NOW() - INTERVAL 3 DAY";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>puntracker</title>
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_config['o_default_style'].'.css' ?>" />
</head>
<body>

<p>
<b>Definitions:</b>  "Torrent File Name" is the name of the file.  You can 
make something up.  "Torrent Hash" has 40 characters.  In Azureus you can right 
click on the torrent, select copy hash and then past here.  "Tracker Announce 
URL" is the URL you used to make the torrent.  It will look something like 
<i>http://www.supertracker.net:6969/announce</i>, announce being the key word. 
"Torrent File Link" is the link to download the actual metadata file.  
<i>http://newmag.org/ericBitchSlapsPimp.torrent</i>. 
So in this field you should enter the URL to the torrent file.  
Please submit a torrent only once and contact us if you have any queries. 
Thanks.
</p>

<!-- this is the form to submit a new torrent -->
<form action="punform.php" method="post">
 <p><b>Torrent File Name:</b> <input type="text" name="name" />
 <b>    Torrent Hash:</b> <input type="text" name="hash" /></p>
 <p><b>Tracker Announce URL:</b> <input type="text" name="announce" />
 <b>    Torrent File Link:</b> <input type="text" name="metadata" />
     <input type="submit" /></p>
</form>

</body>
</html>


<?php

// list all torrents in database.  Name(metadata), seeds, peers, downloads.
$table = $db->prefix.'puntracker';
$result = $db->query("SELECT metadata, name, complete, incomplete, downloads FROM $table 
    ORDER BY name");
    
// can i use $db->fetchArray?  should i change the format?  <p>?
while ($row = $db->fetch_assoc($result)) {
    echo '<p><b>Name:</b> <a href="' . $row['metadata'] . '">'. $row['name'] . '</a>' . 
    ' Seeds: ' . $row['complete'] . ' Peers: ' . $row['incomplete'] . 
    ' Downloads: ' . $row['downloads'] . "</p>";
}

?>

<?php
// let keep tracker within punbb
$footer_style = 'index';
require PUN_ROOT.'footer.php';
?>

2 (edited by eric235u 2007-05-16 15:14)

Re: PHP: Seeing All Errors in Code

i searched around and bumped into this.  :-)

PHP Debugging Basics.


this bugger is useful!

error_reporting(E_ALL);

:-p