CodeIgniter WebServis Veritabanı Hatalarını Yakalamak

Codeigniter ile yürüttüğümüz birkaç web servisimiz mevcut. Bu servislerimiz arka planda olduğu için genellikle veritabanı sorguları ve çalışan sorgulardaki hataları yakalayamıyoruz. Bunun için system/database/DB_driver.php dosyasında birazcık oynayacağız.

display_error fonksiyonunda hataları gösteren yere farklı bir domain/sub domain altındaki servisimize gönderiyoruz. Bu servis üzerinde ise gelen bilgileri alıp Mail olarak yazılım ekibimize gönderiyoruz. Böylece bir hata olduğunda yakalama şansımız yüksek oluyor.

Mail göndermek yerine farklı senaryolarda yapılabilir. Örneğin telegramdan kendinize bildirim gönderebilirsiniz. Başka bir veritabanına hataları yazabilirsiniz. SMS hadi attırabilirsiniz. Monitoring yazılımınız ile entegre edebilirsiniz. Bildirim servisini aktif etmek tamamıyla sizin ihtiyaçlarınıza kalmış bir durum.

Codeigniter içinde system/database/DB_driver.php dosyasında display_function fonksiyonunu örnekteki gibi düzenliyoruz.


function display_error($error = '', $swap = '', $native = FALSE)
{
$trace = debug_backtrace();
$message = '';
foreach ($trace as $call)
{
if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
{
$message .= 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']).'br';
$message .= 'Line Number: '.$call['line'].'br';
break;
}
}

$error_txt = $error;
if( is_array( $error_txt ) )
{
$error_txt = '';
foreach( $error as $key => $value )
$error_txt .= $key.' : '.$value.'br';
}

$html = '
                
<h3> Sunucu : '.gethostname().' - Domain : '.$_SERVER[ 'SERVER_NAME' ].' Database Hatası</h3>

                
<h4>Hata</h4>

                '.$error_txt.'
                
<hr>

                
<h4>Hata Detayları</h4>

'.$message.'
';

$post[ 'message' ] = $html;
$ch = curl_init( "UYARI_WEB_SERVIS_URL" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post ); 
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 1800 );
$result = curl_exec($ch);
curl_close($ch);
exit;
}

system klasörü altındaki işimiz bu kadar. Sonrasında gelen bilgileri “UYARI_WEB_SERVIS_URL” adresine gönderip istediğiniz işlemi yapabilirsiniz. Böylece arka planda olan servislerinizde görünmeyen hataları yakalayabilirsiniz.

“CodeIgniter WebServis Veritabanı Hatalarını Yakalamak” için 2 yanıt

  1. Hello, my name’s Eric and I just ran across your website at diplomasizmuhendis.com…

    I found it after a quick search, so your SEO’s working out…

    Content looks pretty good…

    One thing’s missing though…

    A QUICK, EASY way to connect with you NOW.

    Because studies show that a web lead like me will only hang out a few seconds – 7 out of 10 disappear almost instantly, Surf Surf Surf… then gone forever.

    I have the solution:

    Talk With Web Visitor is a software widget that’s works on your site, ready to capture any visitor’s Name, Email address and Phone Number. You’ll know immediately they’re interested and you can call them directly to TALK with them – literally while they’re still on the web looking at your site.

    CLICK HERE http://www.talkwithwebvisitor.com to try out a Live Demo with Talk With Web Visitor now to see exactly how it works and even give it a try… it could be huge for your business.

    Plus, now that you’ve got that phone number, with our new SMS Text With Lead feature, you can automatically start a text (SMS) conversation pronto… which is so powerful, because connecting with someone within the first 5 minutes is 100 times more effective than waiting 30 minutes or more later.

    The new text messaging feature lets you follow up regularly with new offers, content links, even just follow up notes to build a relationship.

    Everything I’ve just described is extremely simple to implement, cost-effective, and profitable.

    CLICK HERE http://www.talkwithwebvisitor.com to discover what Talk With Web Visitor can do for your business, potentially converting up to 100X more eyeballs into leads today!

    Eric
    PS: Talk With Web Visitor offers a FREE 14 days trial – and it even includes International Long Distance Calling.
    You have customers waiting to talk with you right now… don’t keep them waiting.
    CLICK HERE http://www.talkwithwebvisitor.com to try Talk With Web Visitor now.

    If you’d like to unsubscribe click here http://talkwithwebvisitor.com/unsubscribe.aspx?d=diplomasizmuhendis.com

Uğur Karadeniz için bir cevap yazınCevabı iptal et

%d blogcu bunu beğendi: