Does php run faster without warnings?

后端 未结 3 1329
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 17:42

Since PHP code will run just fine even if it\'s riddled with warnings and notices about undefined indexes and non-static methods being called as static, etc, the question is

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 18:36

    Depends on the amount of warnings, but the error handling in PHP is, even when hiding error messages, relatively expensive.

    What you'd have to do to estimate the effect is profiling on C level: Install valgrind (assuming you're on Linux) and then run

    callgrind /path/to/bin/php /path/to/script.php
    

    this generates a file called callgrind.12345 or so, load this file into an app like kcachegrind and look for php_error_docref0 or php_error_cb to see how much time was spent in the error handler.

    Please mind the cachegrind and valgrind docs when doing that and mind that there are many system-dependant variables involved.

    EDIT: Oh one more note: I assume that way more time is spent while talking to databases and similar systems. and yet another additional note: fixing notices usually makes the code more robust for future changes so it's a good idea independent from performance.

提交回复
热议问题