Welcome Guest, Not a member yet? Register   Sign In
can i echo the size in bytes of a variable?
#1

[eluser]basty_dread[/eluser]
Hello.. i would like to ask if it is possible to print the size of the variable..
i mean for example if how many bytes the variable is holding during loop


Code:
$query = $this->db->query("select pagecontent,pageid from tblpages where pagestatus='1'");
foreach($query->result_array() as $row){
$content = $row['pagecontent'];
$contentid = $row['pageid'];
/// functions to manipulate content here
//includes preg_replace and many more..
}



i dont know if this variable that eats up the memory.. or the query that i do..because on 500 pages i was able to exhaust the 64M of memory allocated for php..
#2

[eluser]WanWizard[/eluser]
One of the downsides of the current Active Record implementation is that the entire resultset is loaded into memory as soon as you call ->result() or ->result_array(). Not needed for database engines that allow seek operations in the resultset.

If you then start looping over the result, and copying information, more memory is needed.

Having said that, PHP doesn't have a sizeof() function that tells you the size of a variable. You could use memory_get_usage() at the beginning and end of one loop, and calculate the difference to get an estimate of the memory used by that loop.
#3

[eluser]basty_dread[/eluser]
thanks for posting @WanWizard..
can you recode my code so that it will not eat up much memory?
Thanks
#4

[eluser]basty_dread[/eluser]
or i will need to allocate more memory so it will not have fatal error?
the code is exhausting 64M of memory allocated for php..
#5

[eluser]basty_dread[/eluser]
do you think this will be ok to use?
mysql_unbuffered_query() than the codeigniter active record?
#6

[eluser]mddd[/eluser]
The right way to go depends on wat the problem is. Try looking at the current used memory every time you start the loop. If it is growing all the time, then you should recode your loop so that it "cleans up after itself".

If the problem is not that the loop is taking up more memory each time, but that the inital loading of results takes too much memory, you could change to loading a small number of results (or just one), work on that, and then move on to the next. Or you could give the script more memory in order to load all records at once and do your stuff.




Theme © iAndrew 2016 - Forum software by © MyBB