I hope you are well... I have a problem and it is that when I try to export more than 500 lines of MYSQL, the server reaches its waiting limit, I would like to know if there is a way to export in the background. i wanna download for example 2k rows.
<?php
$con = mysqli_connect(DATA TO CONNECT) or die ("could not connect to mysql");
mysqli_set_charset($con,'utf8mb4');
session_start();
if(!$_SESSION['user']){
header('Location: pages/login.php');
}
if (isset($_GET['country'])) {
$query = mysqli_query($con,"SELECT * FROM profiles WHERE username='{$_SESSION['user']}' AND status='0' AND country='{$_GET['country']}'");
$token =''.substr(md5("random".mt_rand()),0,10);
$file =$_GET['country']."_".$token.'.txt';
//
$counter = 0;
while($data=mysqli_fetch_array($query)){
//
$counter++;
$current = file_get_contents($file);
$current .= $data['name'].":".$data['country']."\n";
file_put_contents($file, $current);
mysqli_query($con,"UPDATE profiles SET status=1 WHERE id='{$data['id']}'");
if ( $counter >= 200 ) {
break;
}
}
$content = file_get_contents ($file);
header ('Content-Type: application/octet-stream');
header ("Content-Disposition: attachment; filename=\"". basename($file) ."\"");
unlink($file);
echo $content;
}
?>