Is object-oriented PHP slow?

前端 未结 11 1910
温柔的废话
温柔的废话 2020-12-15 06:24

I used to use procedural-style PHP. Later, I used to create some classes. Later, I learned Zend Framework and started to program in OOP style. Now my programs are based on m

11条回答
  •  旧巷少年郎
    2020-12-15 06:42

    If your project contains many files and due to the nature of PHP's file access checking and restrictions, I'd recommend to turn on realpath_cache, bump up the configuration settings to reasonable numbers, and turn off open_basedir and safe_mode. Ensure to use PHP-FPM or SuExec to run the php process under a user id which is restricted to the document root to get back the security one usually gains from open_basedir and/or safe_mode.

    Here are a few pointers why this is a performance gain:

    • https://bugs.php.net/bug.php?id=46965
    • http://nirlevy.blogspot.de/2009/01/slow-lstat-slow-php-slow-drupal.html

    Also consider my comment on the answer from @Ólafur:

    I found especially auto-loading to be the biggest slow down. PHP is extremely slow for directory lookup and file open access, the more PHP function you use during a custom auto-loader, the bigger the slow-down. You can help it a bit with turning off safe-mode (deprecated anyways) or even open-basedir (but I would not do that), but the biggest improvement comes from not using auto-loading and simply use "require_once" with complete fs pathes to require all dependencies per php file you use.

提交回复
热议问题