Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
即使使用
spl_register_autoload( function( $class ) { $file = '/path/to/lib/' . $class; require_once( $file ); return class_exists( $class, false ); } );
xdebug 显示此关闭的总自身成本 (19%) 略低于其包含成本 (25%)。它比 PDO 的 execute() (2%) 高 10 倍。
为什么需要这么多时间?
如果你使用自动加载器,那么你不应该使用 _once 函数,因为它们很慢。使用 require($file) (在我看来,这在您的代码中是错误的,因为您需要不是文件的 $class)。
似乎 xdebug 将包含文件的代码作为闭包的代码。这就是为什么会有这样的结果。我在修改包含文件时发现了它。当我使用 APC 时,执行时间增加了。它影响了关闭的自我成本。