4

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.

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).

I took the time to check the files for basic syntax errors using the following commands:

Edit: I ran the following recursive searches from the root of the website.

find ./ -type f -name \*.php -exec php -l {} \; < ~/php5_basic_syntax_assessment.txt
find ./ -type f -name \*.inc -exec php -l {} \; < ~/php5_basic_syntax_inc_assessment.txt

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.

First, I installed PEAR: [I accepted all the default parameters]

cd ~/
mkdir pear
cd pear
wget http://pear.php.net/go-pear.phar
php go-pear.phar

Next, I installed git:

cd ~/
sudo apt-get update
sudo apt-get install git

Next, I installed PHP Code Sniffer

pear install PHP_CodeSniffer

Finally, I installed the following PHP 5.3 Compatibility standards for the PHP Code Sniffer:

git clone git://github.com/wimg/PHP53Compat_CodeSniffer.git PHP53Compatibility

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.

Finally, here's the command I used to run the PHP Code Sniffer:

phpcs --standard=/home/my_user_name/PHP53Compatibility -p --report-file=/home/my_user_name/php53_assessment.txt /path/to/web/root

To make sure that the specific standards aren't the problem, I also ran the PHP Code Sniffer using the default standards:

phpcs -p --report-file=/home/my_user_name/php53_assessment.txt /path/to/web/root

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.

So, what is causing my PHP Code Sniffer to freeze?

All help is very much appreciated.

Kara
  • 6,115
  • 16
  • 50
  • 57
dqfan2012
  • 117
  • 10
  • CodeSniffer 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. – EkoostikMartin Nov 26 '13 at 14:26
  • Some 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. – dqfan2012 Nov 26 '13 at 14:56
  • For 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. – Greg Sherwood Nov 27 '13 at 03:13

1 Answers1

2

Bit late, but I ran into the same issue. Limit the files to just PHP files should do the trick: phpcs -p -- ./**/*.php

Fabian Marz
  • 219
  • 1
  • 10