Symfony 5 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: - php

I am trying to run
php bin/console make:migration
I received these errors
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
In PDOConnection.php line 27:
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
I have checked all of my .env files. I have configured the
DATABASE_URL=mysql://mylocalDb:#fL3#&_{Dx3N#127.0.0.1:3306/LocalDataBase
I have changed the doctrine config to use server_version: '5.7'. I don't know for sure if that correct. I just removed the # from in front of the line because of the note that said you must configure your server version. But not sure which server it is referring to.
So, my question is how do I test the database connection in Symfony. I have searched the documents and was unable to find a clear answer to this question. When I run
php bin/console doctrine:database:create
This produces an error
In CreateDatabaseDoctrineCommand.php line 82:
Connection does not contain a 'path' or 'dbname' parameter and cannot be created.
I have cleared my cache twice after making config changes and still receive the same error messages.
What other ways can I test the db connection.
https://symfony.com/doc/current/doctrine.html#configuring-the-database

Your DB password contains '#' which breaks Symfony's parser, changing the password to not have the symbol should resolve your issue.

Like ikyuchukov said, the "#" character breaks the parsing. But instead of changing your password, url-encoding this character will do a better job, in my opinion. You can replace it with it's url-encoded value "%40".

Related

phpunit error php_network_getaddresses: getaddrinfo failed: Name or service not known when running composer locally

When i try to run phpUnit locally i get this error:
Runtime: PHP 8.0.25
Configuration: /var/www/html/php-project/phpunit.xml
Warning - The configuration file did not pass validation!
The following problems have been detected:
Line 22:
- Element 'testsuites': This element is not expected.
Test results may not be as expected.
E 1 / 1 (100%)
Time: 00:00.375, Memory: 6.00 MB
There was 1 error:
1) ShoppingCartRepositoryTest::testGetShoppingCart
PDOException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
/var/www/html/php-project/src/Config/ConnectDb.php:17
/var/www/html/php-project/src/Config/ConnectDb.php:24
/var/www/html/php-project/src/Repository/ShoppingCartRepository.php:19
/var/www/html/php-project/test/Repository/shoppingCartRepositoryTest.php:14
Caused by
PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known
Since im new to PHPUNIT i dont know if im missing some sort of configuration, i'll be more than grateful if someone can help.
It's plain php (no frameworks)

RedisException php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

I have Redis and php-redis extension installed but whenever I wanna use a queue in Laravel I just get the error below
RedisException
php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
docker-compose restart redis (or the same name wich you gived your redis-server)

sudden error of QLSTATE[HY000] [2002] php_network_getaddresses

I have been working on an existing laravel API project where they always have a sudden error of
local.ERROR: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution {"exception":"[object] (Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution at /var/www/html/web/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31)
[stacktrace]
sometimes it goes away by restarting the AWS instance or other times it remains there. however, the problem is that it is a running website why this problem is occurring and resolves itself and the website has been down for many hours because of this error and this time restarting the AWS instance doesn't even help.
I can access the database via workbench but can't access it from there website.
what is going on?

JWTRefreshTokenBundle: Name or service not known

We have a working app that successfully returns a token from /auth/user-token using Symfony 4 and Lexik JWT Authentication Bundle. After I install JWTRefreshTokenBundle, (completing the installation up through step 3), however, I get this error when visiting that existing endpoint:
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
Reverting my files to a pre-installation state allows the app to work again.
Does anyone have any ideas about what might be going on here?
===
Update: Attempting to run the installation through step 5 (schema update) results in this error:
In AbstractMySQLDriver.php line 113:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 50:
SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 46:
SQLSTATE[HY000] [2002] Connection refused
You have to install mysql and then add the following line to your .env file at symfony root:
DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name"
Then replace the following values with desired values:
db_user your database user
db_password your database password
db_name your database name
Then do the following changes in config/packages/doctrine.yaml:
doctrine:
dbal:
url: '%env(DATABASE_URL)%'

Sporadic PDOException [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

So I keep sporadically getting the following error:
Type: PDOException
Code: 2002
Message: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
File: /var/www/html/system/db.php
Line: 71
It started randomly after no particular event. I haven't changed anything relating to the database connection etc. I will make some requests, and it will be working fine, then will get this for a few seconds / minutes, then it will go back to working again.
$this->connection = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
My host is similar to the following. Its a subdomain from my ISP, which shouldnt make any difference.
define("DB_SERVER", "name.plus.com:3306");
The machine is self hosted, so no AWS as this similar question here - "PDO exception: php_network_getaddresses: getaddrinfo failed" after changing DNS resolvers, with DB running on AWS
Its running on some docker containers. I have rebooted the actual machine too.
Why would it just randomly be unable to resolve that domain at certain points, and then work fine?

Categories