last day (15 days later) » 

1:56 AM
2
Q: Clear memory being used by PHP

Calvin FroedgeI'm running into an interesting problem. I'm using PHPUnit, and my tests take more memory every single time I run them. Ie... 2.25 MB 2.5 MB 3.0 MB 3.5 MB ....... Does anyone know how to clear out the memory that is being consumed, and can anyone advise me on exploring this in depth? The i...

 
which version of PHPUnit are you using? and roughly what kind of code are you testing? Are you pushing tests to Travis CI?
 
PHPUnit 3.7.8-13-ged6eed8, testing a custom framework. Not pushing tests to Travis CI.
 
TBH: 3.5MB isn't a lot. are these individual tests or you run them one after another using one PHP instance?
 
One of my tests went from consuming 100MB to consuming 500+MB after running it about 10 times.
I run an individual test from command line like this: phpunit tests/unit/Models/MyTest
 
roughly what's in the code if you're comfortable sharing?
 
1:57 AM
Hi
 
hello
 
The test runs test create, updates, deletes, etc. etc. on models
 
to a storage?
 
Every single test consumes more memory each time I run it
To a database
 
you're testing from command line, so I can safely assume that a new instance of PHP is created each time you run the test.
what kind of database is it? did you properly flush / reset the database after you finish the test?
i.e. teardown() setup() methods
 
2:01 AM
mysql database connection
using doctrine dbal
i'm using a singleton to get an instance of it
but i don't understand why this would matter...memory should clear between tests
 
Let's say your code loads all the items from the database.
if your code keeps adding items to your database and you don't reset your database
the number of items in your database keeps increasing
 
ah, yes, i didn't even think about this....
 
hence, if you load the items, your memory usage increases because your items in database increases
you should reset test database with setup and teardown methods in PHPUnit
try writing codes to reset the database and let me know what's the result will you? i'll be fixing some tests on another screen beside
 
I'm pretty sure you're correct...this makes perfect sense
are you sebastian?
or someone who contributes to PHPUnit?
 
no i don't contribute to PHPUnit
I contribute to Packfire Framework for PHP
 
2:07 AM
Very cool
I've been writing my own framework for this project
I'm using a lot of composer packages though
 
cool
let me know if resetting the database fixes the memory consumption problem
 
Testing it now
 
alright
 
that was definitely it...clearing database brought memory usage back down again
Can you recommend any profiling tools to allow me to see which parts are executing most slowly?
and btw please answer the question so I can give you an accepted answer
 
I use Xdebug
alright will do
done
 
2:16 AM
Makes me thinks I can do a better job optimizing my joins and reads
thanks for your help!
 
awesome. no problem at all Calvin. (:
 

last day (15 days later) »