Skip to content

Instantly share code, notes, and snippets.

@smaznet
Last active November 16, 2018 18:29
Show Gist options
  • Save smaznet/f291b37f89fb577573facc44e8d34549 to your computer and use it in GitHub Desktop.
Save smaznet/f291b37f89fb577573facc44e8d34549 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: smaznet
* Date: 7/29/17
* Time: 5:59 PM
*/
header("HTTP/1.1 200 OK");// مهمه چون اگه نباشه تلگرام فک میکنه که سرورتون ارور داده دوباره درخواست میفرسته
define('DEBUG_CHAT','129377043'); // یوزرر ایدی شما یا کانال برای دیباگ
define("TOKEN_DEBUG",TOKEN);// توکن رباتتون
define("DEBUG_TYPE",E_ALL&~E_NOTICE);
// این برای ارور لاگ هاست
function log_error( $num, $str, $file, $line, $context = null ){
log_exception( new ErrorException( $str, 0, $num, $file, $line ) );
}
// اینم برای ارور هایی که بعد از به وجود اومدن باعث میشه کلا ربات بسته بشه
function check_for_fatal()
{
$error = error_get_last();
if ( $error["type"] == E_ERROR )
log_error( $error["type"], "error_get_last: - ".var_export($error,true), $error["file"], $error["line"] );
}
/**
* @param Throwable $e
*/
function log_exception($e)
{
$text = "#err_" . $e->getCode() . "\n\n";
$text .= $e->getMessage() . "\n\n" . $e->getTraceAsString();
$res = @file_get_contents("https://api.telegram.org/bot" . TOKEN_DEBUG . '/sendMessage?' . http_build_query(['chat_id' => DEBUG_CHAT, 'text' => $text]));
}
// میگه قبل بسته شدنش به کدوم فانکشن بگه
register_shutdown_function( "check_for_fatal" );
// چک میکنه اگه قبلش یه ارور بود بگه
check_for_fatal();
// اینم برای اینه که وقتی ارور پیش اومد به کجا بگه
set_error_handler( "log_error",DEBUG_TYPE );
// این برای ارور هاست ولی ارور هایی که وقتی
//try{}catch(Error $e){}
//نزاری پیش میاد
set_exception_handler( "log_exception" );
// این خط هم همه نوع ارور رو فعال میکنه .خطا و اخطارو همه چی
error_reporting( DEBUG_TYPE );
// اینم باید آف بشه چون اگه روشن بشه به هیچکدوم از فانشکن های بالا ارور رو نمیگه
ini_set( "display_errors", "off" );
<?php
include("BOT_Logger.php");// به همین سادگی
/*
*
* اینجا هم کد هاتو بنویس :|
* نطراتتون فراموش نشه
*/
@AboliOneStar
Copy link

عالیه man :|

@parhambarzegar
Copy link

ژان ژااان

@smaznet
Copy link
Author

smaznet commented Jul 29, 2017

@AboliOneStar مرسی جیگر

@AlexSystem32
Copy link

ممنون بابات این مطلب ❤

@AlexSystem32
Copy link

بابت :|

@behradhg
Copy link

behradhg commented Jul 30, 2017

دمت گرم

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment