|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-01-27 23:57 UTC] ryan dot brothers at gmail dot com
Description: ------------ I am seeing an issue in PHP 7 where large database queries are taking up more memory compared to PHP 5.6. In the below example, PHP 7 uses 8.3MB while PHP 5.6 only uses 1.8MB. I have placed SQL to create a test table of 100,000 rows at https://drive.google.com/uc?export=download&id=0B37DKbJklxg_Y3NadnRjc2tVbE0. Is this expected behavior or an issue with PHP 7 memory usage? Thanks for your help. Test script: --------------- <?php $mysqli = new mysqli('localhost', 'test', 'test', 'test'); $mysqli->real_query("SELECT * FROM a"); $result = $mysqli->store_result(); echo memory_get_usage()."\n"; exit; Expected result: ---------------- PHP 5.6.17: 1832472 PHP 7.0.2: 1832472 (or close to it) Actual result: -------------- PHP 5.6.17: 1832472 PHP 7.0.2: 8356704 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 21:00:01 2025 UTC |
Of course, we use only mysqlnd: PHP 7 phpinfo() Client API library version mysqlnd 5.0.12-dev - 20150407 - $Id: f59eb767fe17a6679589b5c076d9fa88d3d4eac0 $ php7.0 -m|grep mysql mysqli mysqlnd pdo_mysql PHP 5 phpinfo() Client API version mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $ php5 -m|grep mysql mysql mysqli mysqlnd pdo_mysql New Example: (mysql table pays with 650k rows, getting ID numbers) ... echo round(memory_get_usage()/1024/1024)."m<br>"; $res=mysqli_query($db,"select id from pays"); echo round(memory_get_usage()/1024/1024)."m<br>"; die(); Output PHP7: 1m 52m Output PHP5: 1m 11m PHP7 need 5 times more memory for each Mysql Query We have debian 8 64 bit + Dotdeb packets with PHP7Using PHP 7.0.15-1~dotdeb+8.1 or 7.1.1 also gives me the same problem in contrast to PHP 5.6 version: executing a simple query thru MYSQLi ("SELECT text FROM table WHERE text LIKE '%url%'"), where the given column is datatype TEXT and the overall result has about 1M of rows. The script exactly always dies upon calling mysqli_query(). PHP 5.6 had a memory limit of 384M which worked fine. I increased the memory limit of 7.0.15-1~dotdeb+8.1 to 2048M and it still wasn't enough! How on earth...? No, mysqli_query() must have changed largely. Or are you telling me PHP 5.6 didn't die on exhausted memory just because the DBMS itself was using more than 2G of memory without reporting it to PHP?