mercredi 6 septembre 2017

Laravel Cron php_network_getaddresses: getaddrinfo failed

Hello!

So I have this annoying problem with setting up a cron job for Laravel scheduling. To understand the problem, Here is the project architecture:

  • The project is set up using docker (we have a container for php,and mysql and for nginx)
  • The web application is built on Laravel 5.3

We want to automatize some tasks, so we created 3 commands and we gathered them inside the schedule to run them every day, here is how the kernel.php looks like:

    protected $commands = [
        'App\Console\Commands\IncompleteAccount',
        'App\Console\Commands\TirageSoon',
        'App\Console\Commands\WinzExpiration',
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('incompleteaccount:run')->everyFiveMinutes()->sendOutputTo(storage_path('logs/cron.log'));

        $schedule->command('tiragesoon:run')->everyFiveMinutes()->sendOutputTo(storage_path('logs/cron.log'));

        $schedule->command('winzExpire:run')->everyFiveMinutes()->sendOutputTo(storage_path('logs/cron.log'));
    }

And our crontab looks like:

* * * * * php /var/www/artisan schedule:run >> /var/www/storage/logs/cron.log 2>&1

In the logs file we get this:

  [Illuminate\Database\QueryException]                                                                                                                                    
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from `booking` where `created_at` > 2017-08-27 16:08:50)  



  [Doctrine\DBAL\Driver\PDOException]                                                             
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known  



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



  [PDOException]                                                                               
  PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known  


No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.

and finally the .env file looks like:

APP_ENV=prod
APP_KEY=base64:gPDQqknmG9YSOMueb/Ii0xXWQvrzOPsVFVRHVIzXXD0=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://www.ourSite.com
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=ourDB
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file

Been facing this problem for 3 days so far! would really appreciate it if you can help! I already saw the similar questions, but nothing worked! Thanks in advance :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire