In the previous article (“A few words about debugging – Part II”) we presented some very helpful extensions which make debugging much easier. Today, we’ll talk about the good practices that everyone should know and use. Let’s go!

3) Good practices

1. Work on a development server

Making even minor changes is risky and an hour-long downtime means a huge financial loss for a large shop. Just to be on the safe side, you should first thoroughly test each modification (even the smallest one) on the development installation.

2. Be careful when uploading the files

You shouldn’t assume that the files will be immediately replaced when you upload the changes to the server. For example, if you send a large file with the styles, it is quite likely that it will take more than 2 seconds to upload (it actually depends on the file size and the connection speed). In this case every user accessing the site during those 2 seconds will download fragmentary styles and the site will be incomplete (assuming that you don’t have styles aggregation/cache).

Updating the PHP scripts is a bigger problem: if you send several scripts, a user accessing the site might see the 500 error, because only part of the correct files will be on the server at a given moment.

To avoid this type of problems, use the maintenance mode.

3. Remember about the backup

Before commencing any work it is good to make a full backup of the site (the files and the database). Additionally, if you make the backup right after enabling the maintenance mode, you can always go back to the previous version without worrying about the data loss.

Remember that you’ll lose all users activities from the time between making the backup and restoring it, if the maintenance mode has not been activated! This will include any orders placed during this time.

4. Write unit tests

Writing the tests isn’t as scary as it might seem at first. It’s true that you need to spend some additional time for every function and method, but eventually it will save you time in the later stages and you won’t deliver faulty code. Automatic tests allow you to detect the errors when the code has been modified.

5. Don’t ignore warnings

Programmers very often ignore warning messages about:

  • using an undeclared variable,
  • using deprecated functions,
  • a problem with opening a file.

The application will work correctly despite the warnings, but you might come across unpredictable behaviour of the application during development, PHP update or simply further use. It might even lead to a critical error of the system, therefore, you should always have the errors messages enabled and take care of all errors/warnings.

Coming soon – the last part of the article series with some practical debugging examples!