Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmeda's avatar

Connection refused (SQL: select * from `users`)

I have a job contains this code:

class SendNotificationToUsersJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(public $request)
    {
    }

    public function handle()
    {
        if ($this->request['type'] == 'all') {
            $users = User::get();
        } else {
            $users = User::find($this->request['user_ids']);
        }

		dd($users);
  }
}

In local the job working perfectly but once I deploy this code on production I got this error in laravel.log:

[2022-05-15 23:05:21] production.ERROR: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users`) {"exception":"[object] (Illuminate\Database\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users`) at /var/app/current/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712)

Even the project working just fine on production and the database exists in production and there is no error while I'm using the app on production!

What I did is put the credentials of the database directly in database.php and the error above is just gone! but I do not want to put it there! So anyone has an idea why this happened ?

I'm using RDS As DB and AWS EB as a server

0 likes
1 reply
okusax's avatar

hi @jean_ali have you cached you .env variables in some way?

Try running

php artisan config:clear
php artisa. config:cache

And restart your queue worker.

Please or to participate in this conversation.