Accessing a file on destruct()

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

My destruct looks like:
PHP Code: [ Select ]
function __destruct()
{
    // Checking if we are to record data
    if($this->record_data)
    {
        // How long our script ran (With everything in between)
        $run_time = substr(microtime(), 0, 10) - self::$run_time;
       
        // Generating the log file contents
        $content .= "Run time: {$run_time};\n";
        $content .= "# of SQL Queries Ran: " . self::$num_queries . ";\n";
        $content .= "SQL Queries Ran: " . implode("\n", self::$queries) . ";\n\n";
       
        // Making sure we handle the errors properly
        try
        {
            // Logging the data
            $this->log($content, $this->record_log);
        }
        catch( exception $e )
        {
            echo $e->getMessage();
            echo '<br /><br />';
            echo nl2br($e->getTraceAsString());
        }
    }
   
    // A special returned variable (Returning length of run-time
    $this->returned = $run_time;
}
  1. function __destruct()
  2. {
  3.     // Checking if we are to record data
  4.     if($this->record_data)
  5.     {
  6.         // How long our script ran (With everything in between)
  7.         $run_time = substr(microtime(), 0, 10) - self::$run_time;
  8.        
  9.         // Generating the log file contents
  10.         $content .= "Run time: {$run_time};\n";
  11.         $content .= "# of SQL Queries Ran: " . self::$num_queries . ";\n";
  12.         $content .= "SQL Queries Ran: " . implode("\n", self::$queries) . ";\n\n";
  13.        
  14.         // Making sure we handle the errors properly
  15.         try
  16.         {
  17.             // Logging the data
  18.             $this->log($content, $this->record_log);
  19.         }
  20.         catch( exception $e )
  21.         {
  22.             echo $e->getMessage();
  23.             echo '<br /><br />';
  24.             echo nl2br($e->getTraceAsString());
  25.         }
  26.     }
  27.    
  28.     // A special returned variable (Returning length of run-time
  29.     $this->returned = $run_time;
  30. }

Just some statistical information I want to log in a log file. I get the following error.
Quote:
The log file ./logs/sql_data.txt does not exist. Make sure it exists.

#0 C:\xampp\htdocs\www\database\database.php(296): database->log('Run time: 0;?# ...', './logs/sql_data...')
#1 [internal function]: database->__destruct()
#2 {main}

Not sure why exactly as the file does exist. I know that the log function works because it logs elsewhere like it's supposed to.

Any help?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

An important note from php.net which I believe may be relevant since you're using relative paths.

Quote:
The working directory in the script shutdown phase can be different with some SAPIs (e.g. Apache).


What happens if you temporarily hardcode the path to the file?
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

That must be it. Didn't catch that note at php.net. It now works. I guess I need to generate an absolute path there to make it work. Or is there a way to make it work?

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 70 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.