Export to PDF and Excel exceeds the php limit


I’m getting the following error trying to export to pdf and excel, I have 21,000 records that I try to export.

[code]Warning: Unknown: POST Content-Length of 18494617 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0
C:\xampp\htdocs\ananas2\third_party\modules\dhtmlx\grid\grid-pdf\generate.php at 13 : Undefined index: grid_xml


My code looks like this

<script src="../../third_party/modules/dhtmlx/grid/dhtmlxgrid_pro.js" type="text/javascript" charset="utf-8"></script>
<script src="../../third_party/modules/dhtmlx/grid/ext/dhtmlxgrid_export.js" type="text/javascript" charset="utf-8"></script>
<script src="../../third_party/modules/dhtmlx/dhtmlxCalendar/codebase/dhtmlxcalendar.js" type="text/javascript" charset="utf-8"></script>        
<script src="../../third_party/modules/dhtmlx/dhtmlxdataprocessor.js" type="text/javascript" charset="utf-8"></script>
<script src="../../third_party/modules/dhtmlx/connector/connector.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="../../third_party/modules/dhtmlx/grid/dhtmlxgrid_pro.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="../../third_party/modules/dhtmlx/dhtmlxCalendar/codebase/dhtmlxcalendar.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="../../third_party/modules/dhtmlx/dhtmlxCalendar/codebase/skins/dhtmlxcalendar_dhx_skyblue.css" type="text/css" media="screen" title="no title" charset="utf-8">
<h1 style='width:95%; padding:20px; font-family:Tahoma;font-weight:normal;background:#f2f3f4;'>Media List Data</h1>
<input class="btn btn-success" type="button" value="Get as PDF" onclick="mygrid.toPDF('../../third_party/modules/dhtmlx/grid/grid-pdf/generate.php');">
<input class="btn btn-success" type="button" value="Get as Excel" onclick="mygrid.toExcel('../../third_party/modules/dhtmlx/grid/grid-excel/generate.php');">        
<div id="medias" style="width:100%; height:500px;background-color:white;"></div>
<div><span id="pagingArea"></span>&nbsp;<span id="infoArea"></span></div>        
<input class="btn btn-success" type="button" value='Add' onclick='add_row();'>
<input class="btn btn-danger" type="button" value='Delete selected' onclick='mygrid.deleteSelectedRows()'>
<div class="smallgray" style="height:90px;"> Double-click or [F2] on <b>cell to edit</b>. Use [Tab] to navigate through cells, [Up/Down] - to navigate through rows.<br></div>         
<script type="text/javascript" charset="utf-8">  
        function onButtonClick(menuitemId, type) {
            var data = mygrid.contextID.split("_");
            mygrid.setRowTextStyle(data[0], "color:" + menuitemId.split("_")[1]);
            return true;
	function add_row(){
		var id = mygrid.uid();
		mygrid.addRow(id, [" ","0"," ","0","0","0","0","0","0","0"]);
    //      My Grid
            mygrid = new dhtmlXGridObject('medias');
    //      Set the path of where the images are located        

    //      Set the text for the header of the grid        
            mygrid.setHeader("Media, Domain, Company, Location, Segmentation, Contacts, Distribution, Media Type, Orientation, Audience, Language");
    //      Attach 2nd level header and selections options        
//      Set the width of the cells row for the grid
//      Set the Column Alignment
//      Set the column types for the grid        

//      Enable Light Mouse Navigation
//      Enable enable hot keys
//      Set skin

//      Initialize

//      Load Data        

//      Set Template        
            mygrid.setPagingTemplates("Pages - [current:0] [current:+1] [current:+2] , from [total] rows","");
//      enable paging and sets its skin;
            mygrid.enablePaging(true, 25, 10, "pagingArea", true, "recinfoArea");

                    if (stage == 2)
//                            refresh_chart();
                    return true;

            var dp = new dataProcessor("data");
            dp.action_param = "dhx_editor_status";

            dp.attachEvent("onAfterUpdate", function(sid, medias, tid, xml){
                    if (medias == "invalid"){
                            mygrid.setCellTextStyle(sid, 2, "background:#eeaaaa");
//                            dhtmlx.message(xml.getAttribute("details"));
//                    else 
//                            dhtmlx.message("["+medias+"] Data saved in DB");

            combo = mygrid.getColumnCombo(3);

            combo = mygrid.getColumnCombo(6);

            combo = mygrid.getColumnCombo(7);
            combo = mygrid.getColumnCombo(8);

            combo = mygrid.getColumnCombo(4);
            combo = mygrid.getColumnCombo(9);

What can be done to solve this issue.

such big data requires much more server resources to process it. You should set bigger values for php options: memory_limit and max_execution_time.
Also we provide solution grid-html-php which was designed to generate excel file with really a lot of data. It generates html-table and force saving as excel file. Excel can understand such file format, but it ask confirmation to open it. You may find grid-excel-php in attachment.
grid-html-php.zip (2.25 KB)

I tried what you suggested, I still have the same issue

I increase the script that uses dhtlmx with the following

ini_set('memory_limit', '512M'); // set the time limit to 240 seconds - 4 minutes ini_set("max_execution_time",240);

I download the file you attached and tried with that, had the same problem.

please, try also to set bigger value for post_max_size.

I added this in my controller

[code]// set memory limit to 256M
ini_set(‘memory_limit’, ‘512M’);
// set the time limit to 240 seconds - 4 minutes

            ini_set('post_max_size', '32M');


It still do not download the pdf or excel file, I can see that there is an action, in the browser - it takes a while after I click the buttons before the download starts, I can see a counter in the browser that goes to 100% - after that I expect the file to start downloading, that do not take place it just stops here.

My question is the controller the right place to put the memory_limit, max execution and post max size, or should I move that to the view or to the dxthml library?

No, you should put them in file generate.php.
It’s used directly, without controller.

hi radyno,

plesa see my other reply :

I need help on this one

I added the statements into the generate.php - it did not make any difference, this is the code for generate/.php for grid excel


ini_set('memory_limit', '512M');
ini_set('post_max_size', '32M');
require_once 'gridExcelGenerator.php';
require_once 'gridExcelWrapper.php';

$debug = false;
$error_handler = set_error_handler("PDFErrorHandler");

if (get_magic_quotes_gpc()) {
	$xmlString = stripslashes($_POST['grid_xml']);
} else {
	$xmlString = $_POST['grid_xml'];
$xmlString = urldecode($xmlString);
if ($debug == true) {
	error_log($xmlString, 3, 'debug_'.date("Y_m_d__H_i_s").'.xml');

$xml = simplexml_load_string($xmlString);
$excel = new gridExcelGenerator();

function PDFErrorHandler ($errno, $errstr, $errfile, $errline) {
	global $xmlString;
	if ($errno < 1024) {
		error_log($xmlString, 3, 'error_report_'.date("Y_m_d__H_i_s").'.xml');
//		exit(1);