{"action":"created","issue":{"url":"https://api.github.com/repos/contao/core/issues/7572","labels_url":"https://api.github.com/repos/contao/core/issues/7572/labels{/name}","comments_url":"https://api.github.com/repos/contao/core/issues/7572/comments","events_url":"https://api.github.com/repos/contao/core/issues/7572/events","html_url":"https://github.com/contao/core/pull/7572","id":54444880,"number":7572,"title":"Vastly improved performance by only calling the error handler if needed","user":{"login":"Toflar","id":481937,"avatar_url":"https://avatars.githubusercontent.com/u/481937?v=3","gravatar_id":"","url":"https://api.github.com/users/Toflar","html_url":"https://github.com/Toflar","followers_url":"https://api.github.com/users/Toflar/followers","following_url":"https://api.github.com/users/Toflar/following{/other_user}","gists_url":"https://api.github.com/users/Toflar/gists{/gist_id}","starred_url":"https://api.github.com/users/Toflar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Toflar/subscriptions","organizations_url":"https://api.github.com/users/Toflar/orgs","repos_url":"https://api.github.com/users/Toflar/repos","events_url":"https://api.github.com/users/Toflar/events{/privacy}","received_events_url":"https://api.github.com/users/Toflar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-15T12:40:54Z","updated_at":"2015-01-15T12:53:47Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/contao/core/pulls/7572","html_url":"https://github.com/contao/core/pull/7572","diff_url":"https://github.com/contao/core/pull/7572.diff","patch_url":"https://github.com/contao/core/pull/7572.patch"},"body":"This pull request improves the performance of **all** Contao installations by an incredible amount of time! I noticed gains in speed of around `50 ms` for a regular Contao setup and up to `100 ms` for setups with a few extensions!!\r\n\r\n### How come?\r\n\r\nContao uses a custom error handler named `__error()` and does set it in the `initialize.php` using `set_error_handler()`. Within that handler, it ignores notices (`E_NOTICE`) completely.\r\nHowever, whenever a notice is raised, the custom error handler is called, because it's set to handle **all** types of errors:\r\n\r\n```php\r\nset_error_handler('__error');\r\n```\r\n\r\nConsidering that we're talking about thousands (!!) of notices, mainly caused by `Undefined index` notices because of a missing `isset()`, this also equals thousands of calls of `__error()`!\r\n\r\n### Solution\r\n\r\n`set_error_handler()` accepts a second parameter where you can specify the error levels you want to register your custom handler for. In our case, we only need it to register for the ones specified in the configuration:\r\n\r\n```php\r\nset_error_handler('__error', Config::get('errorReporting'));\r\n```\r\n\r\nBoom! All the calls for notices have gone and with them a few thousand - completely redundant - calls of `__error()`!\r\n\r\n*Note:* I had to move the `set_error_handler()` call down a bit so that `Config::preload()` is called first.\r\n\r\n### Credits\r\n\r\nI was able to spot that issue thanks to the [PHP profiler blackfire.io](https://blackfire.io) and I would like to thank the developers at SensioLabs for making this excellent product available to everyone!\r\n"},"comment":{"url":"https://api.github.com/repos/contao/core/issues/comments/70081422","html_url":"https://github.com/contao/core/pull/7572#issuecomment-70081422","issue_url":"https://api.github.com/repos/contao/core/issues/7572","id":70081422,"user":{"login":"qzminski","id":193483,"avatar_url":"https://avatars.githubusercontent.com/u/193483?v=3","gravatar_id":"","url":"https://api.github.com/users/qzminski","html_url":"https://github.com/qzminski","followers_url":"https://api.github.com/users/qzminski/followers","following_url":"https://api.github.com/users/qzminski/following{/other_user}","gists_url":"https://api.github.com/users/qzminski/gists{/gist_id}","starred_url":"https://api.github.com/users/qzminski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qzminski/subscriptions","organizations_url":"https://api.github.com/users/qzminski/orgs","repos_url":"https://api.github.com/users/qzminski/repos","events_url":"https://api.github.com/users/qzminski/events{/privacy}","received_events_url":"https://api.github.com/users/qzminski/received_events","type":"User","site_admin":false},"created_at":"2015-01-15T12:53:47Z","updated_at":"2015-01-15T12:53:47Z","body":"+1"}}