News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

David Otton's Blog:
php//memory, Unit Tests
November 18, 2008 @ 15:42:01

In looking to test his fputscsv functionality, David Otton found a simple way to measure its performance by using streams.

Then I realised I could use PHP's (fairly) new IO streams to dump the function's output to a temporary buffer, and read it back in for comparison. Not perfect, but it removes concerns about file mutexes, permissions, unique filenames, etc. and speeds up the tests, as they never touch disc.

He uses a custom stream and points it to php://memory to store and read the data from. Code is included in the post as well as example usage. It runs an assert that the value pushed into another memory chunk is the same as the first one (ensuring that the results of his fputcsv calls are valid).

0 comments voice your opinion now!
memory stream test fputcsv unittest assert


blog comments powered by Disqus

Similar Posts

Sebastian Bergmann's Blog: Improved Skeleton Generator in PHPUnit 3

php-general Mailing List: A Sad PHP Poem

Joshua Thijssen's Blog: PHPShout : a shoutcast streamer in PHP

Jani Hartikainen's Blog: How to make your code testable

Jani Hartikainen's Blog: Unit testing 4: Mock objects and testing code which uses the database


Community Events

Don't see your event here?
Let us know!


laravel symfony2 configure performance conference application php7 podcast introduction framework language opinion api release voicesoftheelephpant part2 example series interview community

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework