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

jpral's avatar

Error while sending STMT_PREPARE packet on queued jobs

Hi there, I have couple of queued jobs connecting to AWS to do some tasks with videos: upload, then re-encode in a couple of formats, and finally moving between buckets. After that I need to save some details in the local mysql database, but as soon as the process takes a bit longer than usual, I keep getting errors with the database:

[2015-07-24 14:44:37] production.ERROR: exception 'ErrorException' with message 'Error while sending STMT_PREPARE packet. PID=1759' in /home/inetwork/public_html/aws/vendor/laravel/framework/src/Illuminate/Database/Connection.php:310
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Error while sen...', '/home/inetwork/...', 310, Array)
#1 /home/inetwork/public_html/aws/vendor/laravel/framework/src/Illuminate/Database/Connection.php(310): PDO->prepare('select * from `...')
#2 /home/inetwork/public_html/aws/vendor/laravel/framework/src/Illuminate/Database/Connection.php(629): Illuminate\Database\Connection->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection), 'select * from `...', Array)

I've looked around for that STMP_PREPARE error and it looks like it's often related to the DB connection to be timed out but I am not sure how to tackle this issue. Any ideas?

0 likes
18 replies
jpral's avatar
jpral
OP
Best Answer
Level 1

For those who might have similar issues in the future: DB::connection()->reconnect() seems to work. In my case I wouldn't see the effect because I'm using a daemon to process the jobs, so they are cached. Don't forget to run php artisan queue:restart if you deploy any changes in your jobs!

1 like
laloutre's avatar

Hi @jpral, I'm having this issue with a queued event listener. From what I could understand, the problem occurs when Laravel tries to restore the serialized model from the event. For instance:

public function handle($event)
{
    $player = $event->player; // <- here
    [...]
}

Can you explain to me how your "DB::connection()->reconnect()" trick would work?

Thanks!

opheliadesign's avatar

Any additional information on this? I'm having this error pop up sporadically all over my 5.1 app.

InstanceOfMichael's avatar

Interestingly, I've verified that this commit is on my server and the queue worker has been reloaded since the pull, but Rollbar is reporting this to me. I don't have a physical log entry for this, so somehow rollbar is receiving this, but my exception handler is not (which should not be possible). I'll reply here if I discover anything more.

GoTesla's avatar

@instanceofmichael or @rebelinblue Did you ever figure out this 'Error while sending STMT_PREPARE packet. PID=1759' that you received related to Laravel queued jobs?

I'm having the same problem on Laravel 5.7.

In the above comments, I don't understand what "DB::connection()->reconnect()" is about and why someone would recommend that because it doesn't seem to address a root cause.

Thanks!

DivDax's avatar

Any news on this? I've the same problem after updating from 5.7 to 5.8.

I'm using:

  • PHP 7.2.17
  • MySQL 5.7.26
  • Redis 3.0.6
  • Horizon
ErrorException: Warning: Error while sending STMT_PREPARE packet. PID=19629
#38 /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(61): Doctrine\DBAL\Driver\PDOConnection::prepare
#37 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(326): Illuminate\Database\Connection::Illuminate\Database\{closure}
#36 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(657): Illuminate\Database\Connection::runQueryCallback
#35 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\Database\Connection::run
#34 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(333): Illuminate\Database\Connection::select
#33 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2124): Illuminate\Database\Query\Builder::runSelect
#32 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2112): Illuminate\Database\Query\Builder::Illuminate\Database\Query\{closure}
#31 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2598): Illuminate\Database\Query\Builder::onceWithColumns
#30 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2113): Illuminate\Database\Query\Builder::get
#29 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(519): Illuminate\Database\Eloquent\Builder::getModels
#28 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(503): Illuminate\Database\Eloquent\Builder::get
#27 /vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(77): Illuminate\Database\Eloquent\Builder::first
#26 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(448): Illuminate\Database\Eloquent\Builder::firstOrFail
#25 /vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(85): App\Jobs\Zipimport::restoreModel
#24 /vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\Zipimport::getRestoredPropertyValue
#23 /vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(45): App\Jobs\Zipimport::__wakeup
#22 [internal](0): unserialize
#21 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42): Illuminate\Queue\CallQueuedHandler::call
#20 /vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(86): Illuminate\Queue\Jobs\Job::fire
#19 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(327): Illuminate\Queue\Worker::process
#18 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\Queue\Worker::runJob
#17 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker::daemon
#16 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Console\WorkCommand::runWorker
#15 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand::handle
#14 /vendor/laravel/horizon/src/Console/WorkCommand.php(46): Laravel\Horizon\Console\WorkCommand::handle
#13 [internal](0): call_user_func_array
#12 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
#11 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::callBoundMethod
#10 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::call
#9 /vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\Container::call
#8 /vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Console\Command::execute
#7 /vendor/symfony/console/Command/Command.php(255): Symfony\Component\Console\Command\Command::run
#6 /vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Illuminate\Console\Command::run
#5 /vendor/symfony/console/Application.php(908): Symfony\Component\Console\Application::doRunCommand
#4 /vendor/symfony/console/Application.php(269): Symfony\Component\Console\Application::doRun
#3 /vendor/symfony/console/Application.php(145): Symfony\Component\Console\Application::run
#2 /vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Illuminate\Console\Application::run
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\Foundation\Console\Kernel::handle
#0 /artisan(37): null
ralphmorris's avatar

@gotesla did you get to the bottom of this at all?

I just started getting this issue also on L.8, redis and horizon.

Warning: Error while sending STMT_PREPARE packet. PID=10968

However it looks like the queue jobs are still going through as they don't appear in the Failed Jobs table. Is this the same for other people?

Also in Sentry I noticed that this Exception is only being report at 'warning' level as opposed to error.

Thanks

DeMexi's avatar

I am experiencing this same issue after an upgrade from Laravel 5.7 to 5.8, although that might be just a coincidence. It only occurs sporadically.

1 like
ahmadt's avatar

Same here, I started to get this error after upgrading to 5.8

1 like
Utchin's avatar

Im getting this error via sentry too.

nmsmith89's avatar

Same here!

Stack:

  • Ubuntu (v18.04)
  • PHP (v7.2.15)
  • Laravel (v5.8.26)
  • Horizon (v3.2.4)
  • Sentry (v1.0.2)

If anyone knows why this happens please let me know!

Qraxin's avatar

I had the same problem with my laravel v6.18.0. And the error stopped coming to Sentry after update sentry/sentry-laravel library from v1.5.0 to v1.8.0 by command composer update sentry/sentry-laravel.

Please or to participate in this conversation.