How to fix a PHP Fatal Error: Allowed memory size of XXX bytes exhausted

How to fix a PHP Fatal Error: Allowed memory size of XXX bytes exhausted

squabtrackersquabtracker Posts: 4Questions: 1Answers: 0

I have tried to setup server side processing, but cannot seem to get it working. When selecting from a table with 130,000 rows I get a alert message that says the following. DataTables warning: tableid=table Ajax error. Please see http://datatables.net/tn/7

My code is working on smaller tables, one of which has 6,500 records and it handles that OK.

I checked the php logs and see the error below.
FastCGI-stderr: PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in

My code is as below where I have set ServerSide to true and type to Post. Is there something else I still need to do?

$(document).ready(function() {
  $('#table').dataTable( {
    "Processing": true,
    "ServerSide": true,
    ajax: {
        url: 'mysql.php',
        type: 'POST'
    },
    "columnDefs": [ { className: "dt-head-left", "targets": "_all" }  ],
    dom: 'Bfrtlip',
    buttons: [ 'copy', 'excel', 'print'  ]
  } );
} );

Any suggestions would be helpful.

Thanks!
James

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    DataTables can't do anything about a PHP out-of-memory error. You could try using ini_set() to increase available memory. Otherwise you could look at the way you are handling the data prior to feeding DataTables.

  • squabtrackersquabtracker Posts: 4Questions: 1Answers: 0

    I thought the point of using ServerSide processing is that datatables didn't ask for all the data at once, and broke it up into pages? Therefore not needing to up the amount of memory that php needs...

    I am using the provided php script to actually get the data, all I did was fill in the column names, so I am not handling the data prior to datatables. https://datatables.net/development/server-side/php_mysql

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918

    I believe that particular script supports HTTP get but your config is using post. If you are using that script then I think you will need to change the Ajax request to an HTTP get so the script can obtain the server side parameters from the URL.

    Kevin

  • squabtrackersquabtracker Posts: 4Questions: 1Answers: 0

    I have tried it with both GET (not specifying in ajax) and also using POST as my code above shows and it doesn't seem to make any difference.

    Is there another example I should follow or check out for the right way to do server side processing?

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin
    Answer ✓

    You've got a typo - it should be serverSide - not ServerSide. Javascript is case sensitive. Likewise for processing :smile:.

    Allan

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Apologies, @squabtracker - I should have spotted that!

  • squabtrackersquabtracker Posts: 4Questions: 1Answers: 0

    I tried allan's suggestion and nothing changed. In looking through the links that were provided I figured out I had the older version of the php script. I changed to the new version (https://datatables.net/examples/data_sources/server_side.html) and got the ssp.class.php file (https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/ssp.class.php)

    After that the correct case for serverSide and processing is working. Thanks @allen!!

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    Excellent. Good to hear you've got it going now.

    Allan

This discussion has been closed.