PHP only stores 1,048,576 characters in an array

I am working on a project that parses huge text files and stores some information in a MySQL database. I noticed that one of the fields did not have information when it was displayed, however, when checking the database (from phpmyadmin) it shows that the data is complete, so there should be a problem with php before the length of the array field is 1048576, whereas in DB - 1235597 characters.

My php info shows that memory_limit is 2048M, the Mysql configuration shows: [Hook] key_buffer = 32M max_allowed_packet = 32M

I don’t know what else could cause the problem ... someone please help !!!

Thanks Sean

+3
source share
1 answer

The default buffer size for PDO is 1 MB (1048576), try overlaying up to 2 MB (2097152)

If you use PDO directly, pass this as the 4th argument

$pdo = new PDO( $dsn, $username, $password, array(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => 2097152) ); 

If you use Laravel, this can be done using the config / database.php file by adding an array of parameters to your connection

 // ... 'mysql' => array( 'driver' => 'mysql', // ... 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'options' => array( PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => 2097152 ), ), // ... 
+1
source

Source: https://habr.com/ru/post/1272186/


All Articles