note 128760 added to mysqlinfo.concepts.buffering
| From: | polygon dot co dot in at gmail dot com | Date: | Tue, 25 Jul 2023 17:20:02 +0000 |
| Subject: | note 128760 added to mysqlinfo.concepts.buffering | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220721@lists.php.net to get a copy of this message | ||
The bufferred and unbuffered queries can be used for a limited amount of records.
For example; while implementing download CSV for a query using buffered way, memory limit issues
comes up above 30,000 records to be buffered.
Similarly, For unbuffered the load switched to database server.
This load on both the web (buffered) and MySQL (unbuffered) servers can be reduced as below
supporting download CSV for 30,000+ records.
<?php
// Shell command.
$shellCommand = 'mysql '
. '--host='.escapeshellarg($hostname).' '
. '--user='.escapeshellarg($username).' '
. '--password='.escapeshellarg($password).' '
. '--database='.escapeshellarg($database).' '
. '--execute='.escapeshellarg($sql).' '
. '| sed -e \'s/"/""/g ; s/\t/","/g ; s/^/"/g ;
s/$/"/g\'';
// CSV headers
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$csvFilename}");
header("Pragma: no-cache");
header("Expires: 0");
// Execute command via shell and echo the complete output as a string
echo shell_exec($shellCommand);
?>
There will be a bit of CPU consumption for the sed regex.
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.168 (proxied: 203.194.96.40)
----
Manual Page -- https://php.net/manual/en/mysqlinfo.concepts.buffering.php
Edit -- https://main.php.net/note/edit/128760
Del: integrated -- https://main.php.net/note/delete/128760/integrated
Del: useless -- https://main.php.net/note/delete/128760/useless
Del: bad code -- https://main.php.net/note/delete/128760/bad+code
Del: spam -- https://main.php.net/note/delete/128760/spam
Del: non-english -- https://main.php.net/note/delete/128760/non-english
Del: in docs -- https://main.php.net/note/delete/128760/in+docs
Del: other reasons-- https://main.php.net/note/delete/128760
Reject -- https://main.php.net/note/reject/128760
Search -- https://main.php.net/manage/user-notes.php