squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

phpcs opens php process with 100% CPU usage #618

Closed kokokurak closed 9 years ago

kokokurak commented 9 years ago

As mentioned here: https://github.com/SublimeLinter/SublimeLinter-php/issues/12

Sometimes, phpcs command opens php process that uses 100% CPU. We found out that it occurs when you test following code:

<?php
foreach

I haven't found any other cases so far.

It's a huge problem when I use real-time sniffing, it always opens such process when I just open new foreach loop and my fan begins to dance.

aik099 commented 9 years ago

So if you run phpcs ThisFile.php on a file with above content it will hang? Same happens with PHP_CodeSniffer 2.3 version was well?

kokokurak commented 9 years ago

@aik099 I'm using the newest PHP_CodeSniffer available in Homebrew, which is 2.3.2.

It doesn't hang when I run just phpcs file.php, but it hangs with phpcs --report=checkstyle --standard=PSR2 file.php

I'm not sure if it's directly related to PHP_CodeSniffer or the linter. Please let me know.

kokokurak commented 9 years ago

I just checked and phpcs --standard=PSR2 file.php (without the report) causes the problem too.

PSR-1 runs just fine: phpcs --standard=PSR1 file.php

gsherwood commented 9 years ago

This is fixed in the current master version and will be released in the next version. The original issue is this one: https://github.com/squizlabs/PHP_CodeSniffer/issues/580

Ideally, PHPCS wouldn't be called on files that contain syntax errors, but I've added a bunch more guard code to make sure PHPCS doesnt break if it does encounter files like this.

Please have a go of the master version if you can.

kokokurak commented 9 years ago

When will the next version be released?

You know, using PHPCS "only on files without syntax errors" is not always possible, I think for the tool like this, working with invalid PHP files is a must.

gsherwood commented 9 years ago

When will the next version be released?

Ideally sometime before the 19th of June or I'm going to get really busy again.

You know, using PHPCS "only on files without syntax errors" is not always possible, I think for the tool like this, working with invalid PHP files is a must.

Hence all my testing and commits. We don't disagree.

kokokurak commented 9 years ago

Great, I can't wait. I use PHPCS with SublimeText all the time :)

dagomar commented 8 years ago

Looks like this now works with 2.4

kokokurak commented 8 years ago

Yes I think it's fixed. I haven't experienced this problem for quite a bit. My fans are quiet :)

kokokurak commented 8 years ago

The problem occurs again after the update. I'm sure it's because of phpcs - I disabled it in Sublime Text and there's no problem anymore.

gsherwood commented 8 years ago

@kokokurak It's probably just another syntax error that is causing the problem. The constant checking of plugins on unsaved files caused this problem, so I need more examples to find more of the problems. If you have a code snippet that causes the problem, please open a new issue and I'll get it fixed up.

rinatkhaziev commented 8 years ago

@kokokurak alternatively you can switch lint mode from background to load/save as a workaround for now.