Laravel MySQL connection compression?

Published 3 months ago by jmar83

Hi there

How to enable MySQL connection compression on Laravel 5.4.x? (I still use PHP 5.6.x) Is that possible? Maybe it's already enabled by default, maybe..?

However, i can't see any options in .ENV file, no MySQL compression true/false or something like that.

When i use PHP mysqli, instead of Laravel MySQL access libraries, then i'm able to enable MySQL connection compression. (I also do that in WordPress, which uses mysqli)

My 2nd question: How can i remove the my gravatar pic as laracasts.com profile picture? I don't want it there...

Thank you for your feedbacks!

With best regards, Jan

jmar83

No anwers, mybe the question is a lil bit too complex for the community. Sorry.

Regards, Jan

Cronix
Cronix
3 months ago (652,820 XP)

Laravel uses PDO, so you can set any extra available pdo options in the options array of the connection. MySQLi is really outdated and not as secure.

http://php.net/manual/en/ref.pdo-mysql.php

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
            'options' => [
                PDO::MYSQL_ATTR_COMPRESS => true
            ]
        ],
jmar83

Thank you very much!! :)

Regards, Jan

jmar83

I think the array $options in the file "Connector.php" is the right place?

Original is:

protected $options = [
        PDO::ATTR_CASE => PDO::CASE_NATURAL,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
        PDO::ATTR_STRINGIFY_FETCHES => false,
        PDO::ATTR_EMULATE_PREPARES => false,
    ];

...but why the ',' after "false" and before '];' ?

I don't think that it makes sense, and i didn't know that it does not result in parsing error.

Is there a special reason for the ',' ?

What is righ now?

That?

    protected $options = [
        PDO::ATTR_CASE => PDO::CASE_NATURAL,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
        PDO::ATTR_STRINGIFY_FETCHES => false,
        PDO::ATTR_EMULATE_PREPARES => false,
        PDO::MYSQL_ATTR_COMPRESS => true
    ];

or that?

    protected $options = [
        PDO::ATTR_CASE => PDO::CASE_NATURAL,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
        PDO::ATTR_STRINGIFY_FETCHES => false,
        PDO::ATTR_EMULATE_PREPARES => false,
        PDO::MYSQL_ATTR_COMPRESS => true,
    ];

Regards, Jan

Cronix
Cronix
3 months ago (652,820 XP)

No. You'll want to read the manual. There's a lot to laravel that you will need to understand.

https://laravel.com/docs/5.6/database

MarkLL

@jmar83 Is there a special reason for the ',' ? It's a coding style more than anything. Both are correct although other languages are more fussy about the last comma.

It's said, that having the extra comma enables you to add extra items to the end and not forget to add the comma - so to speak. It's purely personal.

From http://php.net/manual/en/function.array.php

Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.
jmar83

Hi Mark

Oh, that's really special, i learned a new thing. Thank you very much!!

Regards, Jan

Please sign in or create an account to participate in this conversation.