开发者

jqGrid - High Memory Usage with PHP

开发者 https://www.devze.com 2023-01-28 23:49 出处:网络
I am loading a large amount of data (around 60,000 entries) into a jqgrid based grid (I use paging... makes for close to 3,000 pages at the number of records I am displaying per page) and I find that

I am loading a large amount of data (around 60,000 entries) into a jqgrid based grid (I use paging... makes for close to 3,000 pages at the number of records I am displaying per page) and I find that PHP is using a large amount of memory (over 128mb) which causes an error. I increased the amount of memory available to 256mb and it now works but I am wondering what might cause this and what can I do about it?

The code used in setting up my grid:

jQuery("#tlister").jqGrid({
                url:'/foo/bar/baz', // JSON data
                datatype: 'json',
                mtype: 'POST',
                colNames:['A', 'B', 'C', 'D', 'E'],
                colModel :[
                    {name:'a', index:'a', sorttype:'integer', width:80, editable: true, edittype:'custom', editoptions: { custom_element:custelem,custom_value:custval }},
                    {name:'b', index:'b', sorttype:'integer', width: 80, editable: false},
                    {name:'c', index:'c', width: 150, editable: false},
                    {name:'d', index:'d', width: 150, editable: false, hidden:true},
                    {name:'e', index:'e', width:200, editable: false, formatter: changeTo},
                ],
                editurl:'/foo/bar/bat',
                pager: '#pager',
                pgtext : "Page {0} of {1}",
                rowNum:20,
                loadonce: true,
                rowList:[20,40,60,80,100],
                width: 'auto',
                height: 'auto',
                ca开发者_StackOverflowption: 'Foobar'
            });

EDIT: The ajax request to /foo/bar/baz hits the database and grabs all of the entries for that grid at once. The controller calls a method in the model which returns:

return $this->getTable()->fetchAll()->toArray();

This data is then assigned to the view and the grid uses that. I guess that grabbing 60,000 records is simply expensive and that is the cause of my problem? So perhaps grabbing a limited subset of data on each grid page load would be more efficient?


Hey I think you can use some kind of pagination that every time you change page, an ajax call is done. This way you don't need to load all records to start with.

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:pager


Working example:

http://www.trirand.com/blog/jqgrid/jqgrid.html

Left menu "loading data" - "Json Data"

I think this is what you should do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消