Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is PHP CodeSniffer Freezing?
    primarykey
    data
    text
    <p>I'm a Junior Programmer where I work. Our website was written using PHP 4. We're migrating from PHP 4 to PHP 5.3. There are roughly 5000 PHP files in around 595 directories. So, as you can imagine, the scope of this project is pretty huge.</p> <p>We use Subversion for version control. I have two separate checkouts. I have two VMs that act as separate webhosts - one stack emulates our actual webserver (CentOS 4, PHP4, etc) and the other is a PHP 5.3 stack (Ubuntu 12.04 LTS).</p> <p>I took the time to check the files for basic syntax errors using the following commands:</p> <p>Edit: I ran the following recursive searches from the root of the website.</p> <pre><code>find ./ -type f -name \*.php -exec php -l {} \; &lt; ~/php5_basic_syntax_assessment.txt find ./ -type f -name \*.inc -exec php -l {} \; &lt; ~/php5_basic_syntax_inc_assessment.txt </code></pre> <p>I realize that using php -l to check basic syntax doesn't reveal deprecated code structures/functions and doesn't provide warnings (IE: use preg_slice() instead of slice()). Therefore, I decided to install PHP CodeSniffer.</p> <p>First, I installed PEAR: [I accepted all the default parameters]</p> <pre><code>cd ~/ mkdir pear cd pear wget http://pear.php.net/go-pear.phar php go-pear.phar </code></pre> <p>Next, I installed git:</p> <pre><code>cd ~/ sudo apt-get update sudo apt-get install git </code></pre> <p>Next, I installed PHP Code Sniffer</p> <pre><code>pear install PHP_CodeSniffer </code></pre> <p>Finally, I installed the following PHP 5.3 Compatibility standards for the PHP Code Sniffer:</p> <pre><code>git clone git://github.com/wimg/PHP53Compat_CodeSniffer.git PHP53Compatibility </code></pre> <p>I did all of the above so that I could assess the 5K PHP files in an automated kind of way. It would be extremely tedious and time consuming to go through each file to make sure they manually follow the PHP 5.3 coding standards.</p> <p>Finally, here's the command I used to run the PHP Code Sniffer:</p> <pre><code>phpcs --standard=/home/my_user_name/PHP53Compatibility -p --report-file=/home/my_user_name/php53_assessment.txt /path/to/web/root </code></pre> <p>To make sure that the specific standards aren't the problem, I also ran the PHP Code Sniffer using the default standards:</p> <pre><code>phpcs -p --report-file=/home/my_user_name/php53_assessment.txt /path/to/web/root </code></pre> <p>Either way, the reports freeze in the same place. I've been awake for over 24 hours. I waited for 18 hours before stopping the first run by using CTRL+C. The second is still running and has been running for about an hour and a half.</p> <p>So, what is causing my PHP Code Sniffer to freeze?</p> <p>All help is very much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COCodeSniffer has pretty bad performance. Do you know approx how many LOC are in your 5000 files? The number of files doesn't matter as much as how big they are.
      singulars
    2. COSome of the files are pretty massive. However, after running the standards in verbose mode, I learned that all files were being compared to the standards. There are many kinds of files in our web directory (pictures, pdfs, and other types of binary files). Instead of examining only the files that have PHP, CodeSniffer was comparing all the files in the structure to the specified coding standards. Binary files caused CodeSniffer to stop working. So, after reviewing GitHub documentation, I added the extensions switch to the command to direct CodeSniffer to only check php and inc files.
      singulars
    3. COFor that many files, you might also want to use the current beta (1.5.0RC4) as it includes a complete rewrite of the reporting system to provide big memory savings. The overall performance of the check is going to be based on what sniffs you are using and how much work they are doing on each file, so I can't really comment on the time taken. But I can tell you that PHPCS only checks PHP files by default. Binary files are definitely ignored unless they happen to have a .php, .inc, .css or .js extension. You can confirm the file list by using the -v command line argument.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload