Possible memory leak in all load, find, findone methods

68 views
Skip to first unread message

SoftWord

unread,
Oct 8, 2018, 4:57:40 AM10/8/18
to f3-fra...@googlegroups.com
Hi, made a loop with a simple load() like this:

while(true) {
    $mapper = new Mapper($f3->get('DB'), 'queuesystem');
  $mapper->load(['servicename=?', $serviceName]);  I can use load, find, findone but it's same
}

will cause continue allocation without any free, using pdo or mysqli standard methods memory is same:

To check memory I've used memory_get_usage() function.

ikkez

unread,
Oct 8, 2018, 6:56:40 AM10/8/18
to Fat-Free Framework
that's the nature of the php garbadge collector... you never know when it will kick in and free the memory, but as you overwrite the $mapper var there is probably nothing more to do.. maybe setting it to NULL before reallocating it might help, but I have tried a lot here more than once.. however what does help for intensive tasks is to manually disable the memory limit with ini_set('memory_limit',-1);

SoftWord

unread,
Oct 8, 2018, 8:42:23 AM10/8/18
to Fat-Free Framework
So maybe a class issue related? Because using PDO and mysql_XXXX defaults classes I don't have any issue.

ved

unread,
Oct 8, 2018, 2:24:06 PM10/8/18
to Fat-Free Framework
Is there any reason to initialize the mapper inside the loop?
And is there any difference if you do something like the following:

$mapper = new Mapper($f3->get('DB'), 'queuesystem');
while(true) {

SoftWord

unread,
Oct 8, 2018, 4:51:55 PM10/8/18
to Fat-Free Framework
The memory leak appear everytime you use load/find/findone etc......initiaize inside or outsite it's same.
Try to make only while......new mapper without load, you don't have any leak.
But when you add load etc after 3rd loop leak start.

Vester

unread,
Oct 8, 2018, 5:01:34 PM10/8/18
to Fat-Free Framework
When you iterate over a query that is executed a lot of times, I've found that you should set $log to FALSE to avoid filling up RAM. Mapper uses SQL Class.

exec

Execute a SQL command

array|int|FALSE exec ( string|array $commands [, string|array $args = NULL [, int $ttl = 0 [, bool $log=TRUE ]]] )

The $log is a toggle switch for suppressing or enabling the log of executed commands. You can use it as a profiler as the processing time, in milliseconds, of every SQL command is logged as well.

SoftWord

unread,
Oct 9, 2018, 3:45:19 AM10/9/18
to f3-fra...@googlegroups.com
I can't trust.........it works!!! I've changed sql.php in this way:

/**
* Execute SQL statement(s)
* @return array|int|FALSE
* @param $cmds string|array
* @param $args string|array
* @param $ttl int|array
* @param $log bool
* @param $stamp bool
**/
function exec($cmds,$args=NULL,$ttl=0,$log=FALSE,$stamp=FALSE) {
$tag='';
if (is_array($ttl))


And no memory leaks......

There is only a problem now, I need to use load() for my business, there is a way to disable logs of exec() using load() without change the F3 source code?

EDIT: I've noticed that in this method there is a check:

if ($this->log===FALSE)
$log=FALSE;

and the method:

function log($flag=TRUE) {
...............


so if I call ->log(FALSE);

I can disable logging?

EDIT2:

$db = new SQL(...);
$db->log(FALSE);

make use in loop of ->load(...) = no memory leaks anymore

Thanks all! :)


Richard Goldstein

unread,
Oct 9, 2018, 6:53:27 AM10/9/18
to SoftWord via Fat-Free Framework, Fat-Free Framework

If $sql is your sql object, you can do

 

$sql->log(FALSE);

 

To disable logging.

 

- Rich

 

From: SoftWord via Fat-Free Framework <f3-framework+APn2wQcnFeBkUoDM53w...@googlegroups.com>
Date: Tuesday, October 9, 2018 at 3:45 AM
To: Fat-Free Framework <f3-fra...@googlegroups.com>
Subject: [f3-framework] Re: Possible memory leak in all load, find, findone methods

 

I can't trust.........it works!!! I've changed sql.php in this way:

 

/**
*  Execute SQL statement(s)
@return array|int|FALSE
@param $cmds string|array
@param $args string|array
@param $ttl int|array
@param $log bool
@param $stamp bool
**/
function exec($cmds,$args=NULL,$ttl=0,$log=FALSE,$stamp=FALSE) {
$tag='';
if (is_array($ttl))
 
 
And no memory leaks......
 
There is only a problem now, I need to use load() for my business, there is a way to disable logs of exec() using load() without change the F3 source code?
 

Il giorno lunedì 8 ottobre 2018 23:01:34 UTC+2, Vester ha scritto:

When you iterate over a query that is executed a lot of times, I've found that you should set $log to FALSE to avoid filling up RAM. Mapper uses SQL Class.

 

exec

Execute a SQL command

array|int|FALSE exec ( string|array $commands [, string|array $args = NULL [, int $ttl = 0 [, bool $log=TRUE ]]] )

 

The $log is a toggle switch for suppressing or enabling the log of executed commands. You can use it as a profiler as the processing time, in milliseconds, of every SQL command is logged as well.

 



El lunes, 8 de octubre de 2018, 17:51:55 (UTC-3), SoftWord escribió:

The memory leak appear everytime you use load/find/findone etc......initiaize inside or outsite it's same.

Try to make only while......new mapper without load, you don't have any leak.

But when you add load etc after 3rd loop leak start.

Il giorno lunedì 8 ottobre 2018 20:24:06 UTC+2, ved ha scritto:

Is there any reason to initialize the mapper inside the loop?

And is there any difference if you do something like the following:

 

$mapper = new Mapper($f3->get('DB'), 'queuesystem');
while(true) {
  $mapper
->load(['servicename=?', $serviceName]);
}

 

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/15bd27f0-a449-4b47-8dd6-2545ed7a6b6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages