This topic is locked
[SOLVED]

 How to catch fatal error before that happened?

8/9/2020 5:14:36 PM
PHPRunner General questions
Myr0n author

Hello everybody

Somebody had the opportunity to catch the " Fatal error: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\PHPRunnerProjects\TopSecretProject-v1.06-PR10.4\output\connections\Connection.php on line 626"**

**This error usually happened when the database is not available and a user just open their browser and hit on the url where the project was uploaded.

Unfortunatelly the same error happened when a user is entering data and the network connection or the db is not available.

If we go to the line 626 i found

trigger_error( $message, E_USER_ERROR );



I already customized the error as said here https://xlinesoft.co...r_reporting.htm
Unfortunately the error continue.

I know that could be easy to fix the network connectivity but unfortunately when the IT guys said that the problem is your tablet or laptop wifi you need to find out another solution to let the users know in an elegant way that there is an error and not a technical error that just the programmer knows.

I found that somebody in the forum said "catch the error" but how? because we don't touch the content of connection.php

M
MikeT 8/9/2020

Maybe write some custom code in AfterAppInit() that checks if the db is online and aborts if not(?).

Myr0n author 8/10/2020



Maybe write some custom code in AfterAppInit() that checks if the db is online and aborts if not(?).


Thank you for your reply.

I tried you suggested solution in

AfterAppInit, BeforeLogin & BeforeProcessLogin

withouth success.

Admin 8/10/2020

Database connection may happen before any other event so adding code to events may not help. However, if you create a new Server Database Connection on Output Directory screen in PHPRunner and check your database connection there - it may help.
Also, this error happens on the web server. Any IT guy, who would say that "the problem is your tablet or laptop wifi" is incompetent.

Myr0n author 8/10/2020



Database connection may happen before any other event so adding code to events may not help. However, if you create a new Server Database Connection on Output Directory screen in PHPRunner and check your database connection there - it may help.
Also, this error happens on the web server. Any IT guy, who would say that "the problem is your tablet or laptop wifi" is incompetent.


Do you know what I did with the IT incompetent?
When the database error happened again, I went with my boss to the IT department and took my laptop, connected it to their LAN and showed them that it is not a WIFI connection error and at the same time they showed their incompetence in front of their boss and mine insisting that it was a computer problem, but my boss asked them for one of their laptops and showed them the error.

About what you say to create a connection in the Output directory, you are giving me to understand that I rename the index.php to indexold.php, then create another index.php with the connection to the database, check if there is connectivity and then if there is call indexold.php?
or something similar?

Thank you

Admin 8/10/2020

I'm glad we are on the same page.
I'm not talking about creating any files. Proceed to "Output Directory" screen in PHPRunner, create a new Server Database Connection and then in that code check the connection and display an error message if there is no connection.
https://xlinesoft.com/phprunner/docs/output_directory_settings.htm

Myr0n author 8/11/2020



I'm glad we are on the same page.
I'm not talking about creating any files. Proceed to "Output Directory" screen in PHPRunner, create a new Server Database Connection and then in that code check the connection and display an error message if there is no connection.
https://xlinesoft.co...ry_settings.htm


Good news, thank you so much.

What did I do?

I added the next code to the new Server Database Connection:

$connectTEST = mysqli_connect($host, $user, $pwd, $sys_dbname);

if (mysqli_connect_errno()) {

$catchedErrorMessage = '</H1>'.GetCustomLabel("DATABASE_NOT_AVAIALABLE_AT_THIS_MOMENT").mysqli_connect_error().'</H1>';

$catchedErrorMessage ='<H1>'."Database not available at this moment, please try again later or call at 1-***-***-**** for more information.".'</H1>';

die($catchedErrorMessage);

}


I tried to use GetCustomLabel but does not work.In a near future I am going to implement to send me an email when an error happened.

this is how it looks like

Warning: mysqli_connect(): (HY000/2002): A socket operation was attempted to an unreachable network. in /var/www/**TSP/**connections/ConnectionManager.php on line 145
[size="5"]Database not available at this moment, please try again later or call at 1-**--** for more information.[/size]
Thank you so much for your help.

Myr0n author 8/11/2020

This is a better way to do it:

//

//

try{

mysqli_report(MYSQLI_REPORT_ALL);

$conn = new mysqli($host, $user, $pwd, $sys_dbname);

}

catch (exception $e){

$catchedErrorMessage ='<H1>'."La base de datos no está disponible en este momento, inténtelo de nuevo en algunos minutos
";

$catchedErrorMessage = $catchedErrorMessage ."La base de données n'est pas disponible pour le moment, veuillez réessayer dans quelques minutes
";

$catchedErrorMessage = $catchedErrorMessage ."The database is not available at the moment, please try again in a few minutes</H1>";

die($catchedErrorMessage);

}

mysqli_close($conn);

mysqli_report(MYSQLI_REPORT_OFF);

//



With this way, will not show " Fatal error: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\PHPRunnerProjects\TopSecretProject-v1.06-PR10.4\output\connections\Connection.php on line 626"**



output:
La base de datos no está disponible en este momento, inténtelo de nuevo en algunos minutos
La base de données n'est pas disponible pour le moment, veuillez réessayer dans quelques minutes
The database is not available at the moment, please try again in a few minutes**