We had a little bit of a discussion on twitter about the performance implications of errors in php.

I won’t surprise you as it is (should be) well-known that the error generation and the error suppression is slow. See this blogpost from Derick Rethans: http://derickrethans.nl/five-reasons-why-the-shutop-operator-should-be-avoided.html

So basically @$foo = bar; is slow because:

I’ve just wrote a little benchmark on the issue, available on github

Basically it executes an assigment in a for loop, either using the string ‘foo’ or the non-existent constant foo, which will fallback to ‘foo’ and trigger a notice (I know, it is not a perfect test, because the constant lookup also has some overhead, but still better and more close to the real life issues than trigger_error()).

I mixed this with using the suppress operator and a custom error handler, here are the results:

tyrael@thor:~/checkouts/php-microbenchmarks$ ./src/testError/test.sh
Executing baseline.php

real    0m1.280s
user    0m1.257s
sys     0m0.023s

Executing baseline+error.php

real    0m7.299s
user    0m7.276s
sys     0m0.022s

Executing baseline+error_handler.php

real    0m1.284s
user    0m1.255s
sys     0m0.029s

Executing baseline+suppression.php

real    0m2.035s
user    0m2.011s
sys     0m0.021s

Executing baseline+error+error_handler.php

real    0m20.405s
user    0m20.377s
sys     0m0.021s

Executing baseline+error_handler+suppression.php

real    0m2.000s
user    0m1.973s
sys     0m0.027s

Executing baseline+error+suppression.php

real    0m8.293s
user    0m8.271s
sys     0m0.021s

Executing baseline+error+error_handler+suppression.php

real    0m20.869s
user    0m20.842s
sys     0m0.020s

So my advices: