memory_get_usage() 这个函数,获取当前使用内存量
echo '开始内存:'.memory_get_usage(), ''; $mysql_i=mysqli_connect('127.0.0.1:3306','root','root','online-txjp'); $res=$mysql_i->query("select id from ns_user_sanya_balance_log",MYSQLI_USE_RESULT); $data=[]; while($row=$res->fetch_assoc()){ array_push($data,$row['id']); } $data = implode(',',array_rand($data,10000)); $mysql_i->close(); unset($mysql_i); unset($res); $resdata=[]; $mysql_i=mysqli_connect('127.0.0.1:3306','root','root','online-txjp'); $results=$mysql_i->query("select * from ns_user_sanya_balance_log where id in ($data) ",MYSQLI_USE_RESULT); if($results){ while($rows=$results->fetch_assoc()){ array_push($resdata,$rows); } } $mysql_i->close(); echo '运行后内存:'.round(memory_get_usage()/1024/1024, 2).'MB'; unset($data); echo count($resdata); unset($resdata); echo '回到正常内存:'.round(memory_get_usage()/1024/1024, 2).'MB';
phpstrom 和vscode 开启debug模式的时候也都支持直接查看变量占用内存