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

dru's avatar
Level 3

how can I fix: Packets out of order. Expected 0 received 1. Packet size=68

I installed Laravel in a shared hosting, I placed all the folders of laravel inside a folder called /site, at the same level of public_html, and the contents of public are in public_html. for now, the routes are working, but is not connecting to the database. in fact, is not paying attention to the .ENV file, I even emptied the password and user and it only gives: SQLSTATE[HY000] [2006] MySQL server has gone away

I also changed the max packets to: SET max_allowed_packet = 1024 * 1024 * 512;

and still is not working.

what could I do to at least get an idea and ask for support to fix this.

0 likes
18 replies
Snapey's avatar

if you have tinker, you could write config('database') and check if your .env file is being read

If thats not possible (no command line) then put @dd(config('database')) in a view file and then show that view.

1 like
dru's avatar
Level 3

Hi Snapey, I did a dump(config('database')) and got this:

array:4 [▼
  "default" => "mysql"
  "connections" => array:4 [▼
  "sqlite" => array:5 [▶]
  "mysql" => array:15 [▶]
  "pgsql" => array:12 [▶]
  "sqlsrv" => array:10 [▶]
 ]

So I assume it is actually connecting to the database, right?

Sinnbeck's avatar

Click the little arrow infront of mysql to see what is inside it :)

dru's avatar
Level 3

I did, I can see this, btw, I changed the sensitive data

is thre somewhere what should say is not connected?

array:4 [▼
  "default" => "mysql"
  "connections" => array:4 [▼
    "sqlite" => array:5 [▶]
    "mysql" => array:15 [▼
      "driver" => "mysql"
      "url" => null
      "host" => "127.0.0.1"
      "port" => "3306"
      "database" => "DBNAME"
      "username" => "USERNAME"
      "password" => "PASSWORD"
      "unix_socket" => ""
      "charset" => "utf8mb4"
      "collation" => "utf8mb4_unicode_ci"
      "prefix" => ""
      "prefix_indexes" => true
      "strict" => true
      "engine" => null
      "options" => array:1 [▼
        20 => true
      ]
    ]
    "pgsql" => array:12 [▶]
    "sqlsrv" => array:10 [▶]
  ]
  "migrations" => "migrations"
  "redis" => array:4 [▶]
dru's avatar
Level 3

Ok, I tried checking the connection to the database with:

if(DB::connection()->getDatabaseName()){
     echo "conncted sucessfully to database ".DB::connection()->getDatabaseName();
   }

and is connecting to the database. but bellow that, when I try to bring anything from the database, it fails with SQLSTATE[HY000] [2006] MySQL server has gone away

"Packets out of order. Expected 0 received 1. Packet size=68"

Could it be that the server sucks completely? how could I find this problem to tell the support guy, because he is saying that there are no problems with the server because other sites are working fine (which are php native)

Sinnbeck's avatar

Could you try creating a simple test.php file in the public folder and make a very simple PDO test?

Something like this.

<?php

$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";
try {
$pdo = new PDO($dsn, $user, $passwd);

$stm = $pdo->query("SELECT VERSION()");

$version = $stm->fetch();

echo $version[0] . PHP_EOL;
} catch(Exception $e) {
            echo $e->getMessage();
        }
dru's avatar
Level 3

it returns this: 10.2.27-MariaDB

1 like
Sinnbeck's avatar

Strange. That seems to work. This might work but I am not sure it is best practice. Open database.php and add this to the options array under mysql

'options'   => [
                PDO::ATTR_EMULATE_PREPARES => true
            ],
Sinnbeck's avatar

Do you have any sort of shell access? If so can you then run php artisan cache:clear?

dru's avatar
Level 3

not really, i have shell access but is somewhat limited when I do that command, it returns nothing.

is there a way to do it manually? like deleting files through ftp?

dru's avatar
Level 3

I got someone to clear the cache, and still is giving problems.

Sinnbeck's avatar

Can you show the output of the config('database.mysql') again?

dru's avatar
Level 3

here it is. I modified the dabase, username and password.

array:4 [▼
  "default" => "mysql"
  "connections" => array:4 [▼
    "sqlite" => array:5 [▶]
    "mysql" => array:15 [▼
      "driver" => "mysql"
      "url" => null
      "host" => "127.0.0.1"
      "port" => "3306"
      "database" => "DBNAME"
      "username" => "XXX"
      "password" => "XXX"
      "unix_socket" => ""
      "charset" => "utf8mb4"
      "collation" => "utf8mb4_unicode_ci"
      "prefix" => ""
      "prefix_indexes" => true
      "strict" => true
      "engine" => null
      "options" => array:1 [▶]
    ]
    "pgsql" => array:12 [▶]
    "sqlsrv" => array:10 [▶]
  ]
  "migrations" => "migrations"
  "redis" => array:4 [▶]
]
Sinnbeck's avatar

Oh sorry please press the arrow in front of options

dru's avatar
Level 3

here is the modification I did to the dabase.php

http://i.imgur.com/0O9Igvn.png

array:4 [▼
          "default" => "mysql"
          "connections" => array:4 [▼
            "sqlite" => array:5 [▶]
            "mysql" => array:15 [▼
          "driver" => "mysql"
          "url" => null
          "host" => "127.0.0.1"
          "port" => "3306"
          "database" => "xxx"
          "username" => "xxx"
          "password" => "xxx"
          "unix_socket" => ""
          "charset" => "utf8mb4"
          "collation" => "utf8mb4_unicode_ci"
          "prefix" => ""
          "prefix_indexes" => true
          "strict" => true
          "engine" => null
          "options" => array:1 [▼
            20 => true
          ]
        ]
dru's avatar
Level 3

FINALLY GOT IT WORKING!

to fix it, the config at the .env file was changed from DB_HOST=127.0.0.1 to DB_HOST=localhost

thanks for all of those who helped!

1 like
Sinnbeck's avatar

Great to hear. I would suggest telling your provider so that they can tell others with the same issue

3 likes

Please or to participate in this conversation.