Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Owdy on May 16, 2005, 10:32:20 AM

Title: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 10:32:20 AM
When forum (mysql) goes down, i get white page with warning text. But in main site where i use SSI, that just brokes that page with random php warnings. Quoestion, how can i make my main site use that same error page as forum does? Can i make custom one?
Title: Re: Connection problems and other notises and SSI
Post by: rakuli on May 16, 2005, 10:59:15 AM
PHP Error Handling (http://au.php.net/errorfunc)

You can look at adding some error handling functions to your SSI.php or on the page in question. There's tonnes of things you can do with errors. Or you can just turn them off.

Code: [Select]
error_reporting(0);
Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 11:24:33 AM
I am not my own host. I cant edit php.ini.
Title: Re: Connection problems and other notises and SSI
Post by: rakuli on May 16, 2005, 11:27:58 AM
You can add it to the script. You don't need to touch the php.ini.

For example you could just go

Code: [Select]
<?php require(&#39;ssi.php&#39;); error_reporting(0); ?>
<html>
.....your page
</html>

Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 11:37:07 AM
Hmm,okay. How do i ad it in my main site? Do i make some error.php page or ad that code in my current page? I want it to show only that when fatal error appears.
Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 11:49:57 AM
I use this:

Code: [Select]
<?php
;
$ssi_ban true;
ob_start();
require(
"/www/asiakkaat/hoitajat/public_html/foorumi/SSI.php"); if (!$db_connection || !@mysql_select_db($db_name$db_connection))
db_fatal_error();
if (
$maintenance == 2)
db_fatal_error();
 
?>

It gives correct error notice but with error:

Quote
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /www/asiakkaat/hoitajat/public_html/foorumi/Sources/Subs-Auth.php on line 311

How do i adjust it?

Or better, how can i make my own message?
Title: Re: Connection problems and other notises and SSI
Post by: rakuli on May 16, 2005, 12:12:44 PM
In your SSI.php you could do something like this for a failed connection to the database.

FInd




// Connect to the MySQL database.
if (empty($db_persist))
$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
else
$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
if ($db_connection === false)
return false;


Change to


// Connect to the MySQL database.
if (empty($db_persist)){
$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
                if (!$db_connection){
                echo     "Unfortunately we are unable to connect to the database at this time. Please try again later";
                     exit();

                }
    }
else{
$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
              if (!$db_connection){
                echo     "Unfortunately we are unable to connect to the database at this time. Please try again later";
                     exit();
           }
}
if ($db_connection === false)
return false;

Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 12:24:08 PM
No, i dont want hack SSI.php :)
Title: Re: Connection problems and other notises and SSI
Post by: [Unknown] on May 16, 2005, 01:18:53 PM
Doesn't it already return false when you have problems?

You could do:

$ssi = include('SSI.php');

if (!$ssi)
   die;

-[Unknown]
Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 01:25:20 PM
Doesn't it already return false when you have problems?

With basic SSI i get fatal erros, see attacment.

If i use this in top of my page
Code: [Select]
<?php
$ssi_gzip 
true;
$ssi_ban true;
ob_start();
require(
"/www/asiakkaat/public_html/foorumi/SSI.php"); 

if (!
$db_connection || !@mysql_select_db($db_name$db_connection))
db_fatal_error();

if (
$maintenance == 2)
db_fatal_error();
?>
, i get this:

Quote
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /www/asiakkaat/public_html/foorumi/Sources/Subs-Auth.php on line 311
Connection Problems
Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.


You could do:

$ssi = include('SSI.php');

if (!$ssi)
   die;

Thanks, i try that.
Title: Re: Connection problems and other notises and SSI
Post by: [Unknown] on May 16, 2005, 01:27:00 PM
You're not going to have template_menu if SMF died.

-[Unknown]
Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 01:31:47 PM
Tryed this, got blank page

Quote
<?php
$ssi_gzip = true;
$ssi_ban = true;

$ssi = include('/www/asiakkaat/hoitajat/public_html/foorumi/SSI.php');

if (!$ssi)
   die;
ob_start();
?>
I dont want blank page, i want to show  message :)
Title: Re: Connection problems and other notises and SSI
Post by: [Unknown] on May 16, 2005, 01:33:04 PM
So, instead of die;, use:

{
   echo 'Ding, dong, the server\'s dead... the server\'s dead.... please come back later.';
   die;
}

-[Unknown]
Title: Re: Connection problems and other notises and SSI
Post by: Owdy on May 16, 2005, 01:49:55 PM
LOL, okay :D

edit: this is perfect solution. Thanks !!  :)

Code: [Select]
<?php
$ssi_gzip 
true;
$ssi_ban true;
ob_start();
$ssi = include(&#39;/www/asiakkaat//public_html/foorumi/SSI.php&#39;);

if (!$ssi)
   {
   echo &
#39;Serverillä näyttää olevan ongelmia. Ole hyvä ja yritä myöhemmin uudelleen.&#39;;
   
die;
}
?>

Does that code look okay to you? Im not eaven sure what that ob_start(); is.  :D