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

ojessecruz's avatar

Laravel 11 :SQLSTATE[HY000] [2002] Connection refused

Hey guys, need some help here.

I am upgrading to Laravel 11, but I am getting some errors when I am deploying my app on Vapor.

The problem is on Task Scheduling, when I run some querys to get the days and hour that the user input as a parameter to run the jobs.

code:

$hour = Parameter::getParameter(Parameter::TIME_BILLING_AUTO_REGISTER);

Schedule::command("auto-register:daily") ->timezone("America/Chicago") ->dailyAt($hour);

The error:

Generating optimized autoload files

Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover --ansi Illuminate\Database\QueryException SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select * from parameters where key = WEEKLY_BILLING_DAY limit 1) at vendor/laravel/framework/src/Illuminate/Database/Connection.php:813 809▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 810▕ ); 811▕ } 812▕ ➜ 813▕ throw new QueryException( 814▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 815▕ ); 816▕ } 817▕ } +22 vendor frames 23 app/Models/Parameter.php:61 Illuminate\Database\Eloquent\Builder::first() 24 routes/console.php:47 App\Models\Parameter::getParameter() Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1 Error: Process completed with exit code 1.

Important things:

  • This works on Laravel 10.
  • The credentials not seem to be the problem, since Laravel 10 works and if I remove the line the deploy works and the application works fine as well.

Any ideias?

0 likes
4 replies
Snapey's avatar

why two different enums in the line you say breaks the app and the enum in the error?

ojessecruz's avatar

@Snapey sorry, just copy an example. Here is the correct enum.

$weekDay = Parameter::getParameter(Parameter::WEEKLY_BILLING_DAY);

$monthlyDay = Parameter::getParameter(Parameter::MONTHLY_BILLING_DAY);

$biMonthlyDay = explode( ";", Parameter::getParameter(Parameter::BIMONTHLY_BILLING_DAY) );

$hour = Parameter::getParameter(Parameter::TIME_BILLING_AUTO_REGISTER);

Schedule::command("auto-register:daily") ->timezone("America/Chicago") ->dailyAt($hour);

ojessecruz's avatar

Ok... I found the problem.

The problem is at the time those querys are running, the ENV variables wasn't loaded yet.

Trying some options here.

v16Studios's avatar

@ojessecruz Hi! I was encountering this issue when using GitHub actions. For me it appears it was because the CACHE_DRIVER env var name has changed to CACHE_STORE, the default value is also now database and not file. So if your env is still using CACHE_DRIVER then it's possible it could be loading the new default CACHE_STORE var instead.

Just to note, if it's not the cache specifically for you, then perhaps some other var name has also changed, or it's default value is now different.

Please or to participate in this conversation.