Jump to content

Php error logging


Philwn

Recommended Posts

will the following code work to log any php errors i may have on the page this code is included?

 

ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);
ini_set('log_errors',TRUE);
ini_set('html_errors',FALSE);
ini_set('error_log','./error_log.txt');
ini_set('display_errors',FALSE);

Link to comment
Share on other sites

log them to a file, ive been suggested to log any php errors to a file so I can see if this is the case of my too many processes?. I dont have access to the php.ini file but have been told if I create one in the same folder as my files it will work but there seems to be alot of confusing information about logging php errors and where the php.ini is.

Link to comment
Share on other sites

because the scripting was disabled earlier the logs didnt work but they are now. The logs shows quite alot of errors. some of which are the following:

 

[Wed Sep 21 11:08:19 2011] [error] [client 77.103.33.216] PHP Warning:  fwrite(): supplied argument is not a valid stream resource in /home/sites/myurl.co.uk/public_html/Range.php on line 140, referer: http://www.myurl.co.uk/Range/En/Accessories/Accessories/

    fwrite($fp, ob_get_contents());

yet if I visit that page the cached file is shown which means fwrite worked at some point?

 

[Wed Sep 21 11:08:19 2011] [error] [client 77.103.33.216] PHP Warning:  fclose(): supplied argument is not a valid stream resource in /home/sites/myurl.co.uk/public_html/Range.php on line 144, referer: http://www.myurl.co.uk/Range/En/Accessories/Accessories/

fclose($fp); 

[Wed Sep 21 11:08:22 2011] [error] [client 77.103.33.216] PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/myurl.co.uk/public_html/Range.php on line 91, referer: http://www.myurl.co.uk/Range/En/Accessories/Accessories/

while($row_QA = mysql_fetch_array($list_QA))

this is because there are no results so I guess i need to just say if (mysql_fetch_array(list_QA)<1) die or something?

 

code for whole page:

<?php 
   $cat = $_GET["cat"];
   $sub_cat = $_GET["sub"];
   $language = $_GET["lang"];
$cachefile = "cache/".$cat."-".$sub_cat."-".$language.".html";


      $cachetime = 60 * 60 * 96; // 5 days


      // Serve from the cache if it is younger than $cachetime

      if (file_exists($cachefile) && (time() - $cachetime
         < filemtime($cachefile))) 
      {

         include($cachefile);


         echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." -->";


         exit;

      }

      ob_start(); // start the output buffer
include("./includes/db_con.inc.php");
$page_title = $cat . " - " . $sub_cat;
$sql_meta = mysql_query("SELECT * FROM sub_cat WHERE name='$sub_cat'");
$row_meta = mysql_fetch_assoc($sql_meta);
$meta_desc = $row_meta['META_DESC'];
$meta_key = $row_meta['META_KEY'];
include("./includes/head.php"); 
include("./includes/header.php");
mysql_free_result($sql_meta);
  ?>

<div id="main-page-header">
<?php 
$desc_sql = mysql_query("SELECT * FROM sub_cat WHERE name='$sub_cat'");
$row_desc = mysql_fetch_assoc($desc_sql);
$description = $row_desc['description'];
echo "<img src='$img_loc/product-pages/sub-cat-head/".str_replace(" ", "-", $row_desc['name'])."-sub-cat-head.jpg' width='940' height='310' />";
mysql_free_result($desc_sql);
?>
</div>

  <div id="page-content">
  
    <div id="main-page-text">
    
    <h1><?php echo $sub_cat; ?></h1>
<h2 class="crumbs"><a href="<?php echo "$url/Products/$lang/"; ?>">Products</a> > <a href="<?php echo "$url/Category/$lang/".urlencode($cat)."/"; ?>"><?php echo $cat; ?></a> > <?php echo $sub_cat; ?></h2>
<p>
<?php echo $description; ?>
</p>

  <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="170" font="verdana"></fb:like>

    
  <div id="related-wrap">
  
  <h2><?php echo $sub_cat; ?> Products</h2>
    
    <?php
$range_products = mysql_query("SELECT * FROM $table WHERE CATEGORY='$cat' AND SUB_CATEGORY='$sub_cat' AND display='1' ORDER BY sortID ASC");
while($row_range = mysql_fetch_array($range_products))
    { 
$prodid = str_replace("/", "-", $row_range['PRODID']);
$cat_link = urlencode($row_range['CATEGORY']);
$sub_cat_link = urlencode($row_range['SUB_CATEGORY']);
echo "<div class='related-products'>\n<a class='related-img' href='$url/Product/$lang/$cat_link/$sub_cat_link/$prodid/'>\n<img src='$img_loc/product-pages/Range-thmb/$prodid.jpg' width='120' height='120' /></a>\n";
    echo "<h5>" . $row_range['PROD_TITLE'] . "</h5>\n";
    echo "</div>\n";
}
mysql_free_result($range_products);
?>

    </div>    
    
     <div id="FAQ-wrap"><h2>Frequently Asked Questions</h2>
  <?php
  $QA_table = $lang . "_qanda";
  if ($id=="") {
      $list_QA = mysql_query("SELECT * FROM $QA_table WHERE SUB_CATEGORY='$sub_cat' AND DISPLAY='1'");
  }
  else {
  $list_QA = mysql_query("SELECT * FROM $QA_table WHERE PRODID='$id' AND DISPLAY='1'");
	}
  while($row_QA = mysql_fetch_array($list_QA))
{ 
  echo "<div id='FAQ-QA'>";
  echo "<h2 class='FAQ-question'>Q: ".$row_QA['QUESTION']."</h2>";
     echo "<p class='FAQ-question'>A: ".$row_QA['ANSWER']."</p></div>";
}
mysql_free_result($list_QA);
  ?> 
    <div id="FAQ-question">
        <h2 class="white">Got a question about the 
        
        <span class="got-question-product"><?php echo $sub_cat; ?></span> 
        
        </h2>
      </div>
      
      </div>

    

    </div>


    
    <div id="totem-menu-container"><?php include("./includes/search.php") ?>
    
    <?php include("./includes/totem.php") ?>
    
    </div>
  
  </div>
  </div>
<!-- MAIN CONTENT OF PAGE BELOW HERE -->

<!-- END MAIN CONTENT OF PAGE BELOW HERE -->

  
  
  
<?php include("./footer.php") ?>

<?php
       // open the cache file for writing
       $fp = fopen($cachefile, 'w'); 


       // save the contents of output buffer to the file
    fwrite($fp, ob_get_contents());

	// close the file

        fclose($fp); 

	// Send the output to the browser
        ob_end_flush(); 
?>
   
   
   

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.