The Zend_Search_Lucene instance performs some work at exit time
if any documents were added to the index but not written to a new segment.
It also may trigger an auto-optimization process.
The index object is automatically closed when it, and all returned QueryHit objects, go out of scope.
If index object is stored in global variable than it's closed only at the end of script execution [20].
PHP exception processing is also shut down at this moment.
It doesn't prevent normal index shutdown process, but may prevent accurate error diagnostic if any error occurs during shutdown.
There are two ways with which you may avoid this problem.
The first is to force going out of scope:
<?php
$index = Zend_Search_Lucene::open($indexPath);
...
unset($index);
And the second is to perform a commit operation before the end of script execution:
<?php
$index = Zend_Search_Lucene::open($indexPath);
$index->commit();
This possibility is also described in the "Advanced. Using index as static property" section.
[20] This also may occur if the index or QueryHit instances are referred to in some cyclical data structures, because PHP garbage collects objects with cyclic references only at the end of script execution.




