There is a system written in laravel5.2 running on a server with ubuntu (16.04 64bit) and lamp (php7, mysql5.7, apache2).

The system has a task that runs on a schedule and runs for about half an hour, the problem is that the task is not completed until the end, and it writes an exception to the log:

PDOException: SQLSTATE[HY000] [2002] Connection refused in /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55 

That is, the connection with the database initially works, then after about 12 minutes, with the next request, laravel tries to update the connection, and then drops with this exception.

Googling problems gave advice to change the host in .env from localhost to 127.0.0.1, this did not help.

At the same time, this problem is not observed on the local machine on mamp and the task is fully executed.

What could be the problem?

  • Also everywhere else they advise Port to check, did you check the port is the same? - Orange_shadow
  • Yes. If the port was specified incorrectly, the error would be dropped upon the first request. A certain number of requests are immediately executed, and after 12 minutes it drops - nullproduction
  • And you could put the base queries? And are you sure that something is being done? Maybe he konkitsya you just many times but never connect, and then throws an exception. Do the php settings for the console application match the settings for the server? I remember I had a problem when the PDO did not stand for PDO at all, I also broke my head for a long time, until I saw that I had 3 php.ini - Orange_shadow
  • Sure. I see fresh records in the database. As for the console and server, I do not know where to look at it. For the console, a separate php.init should be? The fact that pdo from the console works 100% - nullproduction
  • Well, it should not, but it can be so (a few php.ini), ok, but can you see the database log, does it throw any exceptions there? maybe what timeout time it is - Orange_shadow

1 answer 1

It helped to increase tamaut in the mysql settings.

 wait_timeout = 99999999999 interactive_timeout = 999999999