Is there a function in PHP to query the number of open files?
Sort of like memory_get_usage()
but for open files.
I'm running the unit test suites for Zend Framework. The problem is that after it gets through the tests for Zend_Search_Lucene, subsequent tests start failing. But if I skip the Zend_Search_Lucene tests, all the test suites succeed.
I'd like to prove that Zend_Search_Lucene (or any other test suite) is opening too many files and not cleaning up after itself. I thought PHP might have a function to simply report how many files are open. But after 20 minutes of searching the PHP manual and Google, I can't find any such function.
There is no such function in PHP.
But there are alternatives. If you are running linux/unix/OSX, then running lsof from command line can give you that information.
This could be combined with a custom Test listener for PHPUnit - I described the approach under a different question - How to wrap PHPUnit to control command line reporting?
PHPUnit_Framework_TestListener interface has methods like startTest(), endTest(), startTestSuite(), endTestSuite(). You could execute a shell_exec call to lsof from those methods and print out the interesting numbers before and after every test/testsuite.