If database is not available there is some seconds of loading. Then the log shows this error, should'nt that trigger the exception handler? (other errors end up their as expected)
[2021-04-14 13:01:40] production.ERROR: SQLSTATE[HY000] [2002] Connection timed out (SQL: SELECT * FROM `list` LIMIT 1) (View: /opt/app-root/src/resources/views/err1.blade.php) {"exception":"[object] (Facade\\Ignition\\Exceptions\\ViewException(code: 0): SQLSTATE[HY000] [2002] Connection timed out (SQL: SELECT * FROM `list` LIMIT 1)
Then I see "504 Gateway Time-out The server didn't respond in time." Error. How do I configure eloquent so a database timeout throws a regular exception? (so the handler can show a more appealing standdard error page)
I tried to set the PDO options to PDO::ERRMODE_EXCEPTION in config/database.php and thenphp artisan config:clear
but it did not work.
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'forge'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
'options' => [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,]
],
The reason you are getting a504 Gateway Time-out
error is because when you perform a query with a database that does not exist, it takes a very long time (around 2mins for me).
I suspect your max execution time by your web-server or php config is lower than that, and therefore generates a504 Gateway Time-out
error.
There is 2 ways to fix this:
Increase your max execution time in your server by adjusting your server config file:
Also increase yourmax_execution_time
time in your php.ini file (make sure to change the one used by the web-server, not just the CLI one). or add this at the start of index.php:
ini_set('max_execution_time', 1200); // 1200 seconds
Use the following options:
'options' => [PDO::ATTR_TIMEOUT=> 10, // timeout in seconds]
Note that the actual timeout was often larger than the specified timeout for some reason. My tests showed that having a timeout of 10 seconds, actually timed out at 40sec. And 20 seconds timed out at 80sec. I don't know why this is. Your experience may vary.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.