ZF-4057: Zend Loader produces a lot of unnecessary "file not found" warnings

Issue Type: Improvement Created: 2008-08-25T05:27:04.000+0000 Last Updated: 2011-08-21T17:03:20.000+0000 Status: Resolved Fix version(s): Reporter: Alucard (alucard) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Loader

Related issues: - ZF-2985



The Zend Loader component will produce a lot of "file not found" warnings because it uses 'fopen' to probe the existence of files.

Instead of using fopen directly, why not use file_exists first to test for the existence and then use 'fopen' to open the files??

This should be an easy fix.


Posted by old of Satoru Yoshida ( on 2008-08-29T06:41:24.000+0000

I think it duplicates ZF-2985.

Posted by Matthew Weier O'Phinney (matthew) on 2011-08-21T17:03:20.000+0000

We prefix fopen() with the "@" to silence such warnings; if you're seeing them, they're likely showing up in your logs or you have ext/scream enabled. While we'd prefer not to have these warnings at all, there are some reasons for them.

The fix isn't as easy as you might expect. Because this functionality is used everywhere, and because it may be invoked sometimes thousands of times in a request, we run into performance issues. Every stat call you do is an I/O call to the disk -- and these are very expensive. Add to this the fact that loadClass() and isReadable() are actually testing against the include_path: the result is that if the file we're looking for is N directories into the path, we end up having N*2 stat calls until we reach our file... if indeed it's ever found and/or readable. (This is actually why we use fopen() -- because it looks on the include_path. Unless you have PHP >=5.3.2 which introduces stream_resolve_include_path(), there's no other function in PHP that has the ability to test against the include_path without userland iteration.)

This last is also why file_exists() will not work -- because we're testing a file against the include_path. To use file_exists() correctly in this situation, we'd have to iterate the include_path and test against each segment until we got a hit, or all paths had been tested.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.