I’ve seen quite a lot of PHP developers don’t have PHP debugger installed on development enviornment. Instead of debugging PHP code line by line, we’re fond of echo and print the results on the web page to find the errors.

It would be hard in the past because we don’t have good PHP IDE until we have PHPStorm. Unfortunately PHPStorm doesn’t have debugger installed in the environment and we have to install it by ourselves.

Download xdebug

1
git clone git://github.com/xdebug/xdebug.git

Install XDebug

1
2
3
4
5
cd xdebug
phpize
sudo ./configure –enable-xdebug
sudo make
sudo make install

NOTE: After the installation, it will output the path of debug.so from the command line. Save it and paste into zend_extension to the configuration setting in next step.

Paste the following code to php.ini

1
2
3
4
5
6
7
zend_extension=/usr/lib/php/20151012/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.idekey=PHPSTORM
xdebug.remote_port=9000
xdebug.remote_log=/var/log/xdebug.log

https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel

Sometimes we need to enable the MySQL log to see what SQL scripts have been created by our application. This is a way to enable MySQL log.

  1. Login to mysql in command line
  2. Run the scripts below:
1
2
3
4
/* For Mac OS */
SET global log_output = 'FILE';
SET global general_log_file='/Applications/MAMP/logs/mysql_general.log';
SET global general_log = 1;
1
2
3
4
/* For Linux */
SET global log_output = 'FILE';
SET global general_log_file='/var/log/mysql/mysql_general.log';
SET global general_log = 1;

It can be turned off with:

1
SET global general_log = 0;

There are thousands of linux commands available. But there are only a few commands we use for most of the time. As a result, we don’t have to learn and recite all the commands. Of course we can check the manuals by “man” or google it but it’s not a fast way for me to search them all the time. Therefore, I list them all together as a cheat sheet.

System info

1
2
3
4
5
6
7
8
9
10
11
12
13
date    ## show the current date and time
cal ## show this month's calendar
uptime ## show current uptime
w ## display who is online
whoami ## who you are logged in as
finger user ## display information about user
uname -a ## show kernel information
man `command` ## show the manual for command
df ## show disk usage
du ## show directory
free ## show memory and swap usage
whereis app ## show possible location of app
which app ## show which app will be run by default

Read More

I’ve been working on PHP for more than 5 years time. As far as I can find, there are still a lot of companies using PHP with version lower than 5.6. Especially some e-commerce stores like Woocommerce, Magento 1.x. Most of the owners won’t upgrade PHP because the systems are still working fine. There’s no way to spend money on something unnecessary. As a result, developers should keep the PHP version in mind when we need to build new feature or do some bug fixes for the old system.

The current version of PHP is 7.1. But there are more than 50% of users are still using PHP 5.x[1] and some PHP versions are end of officially supported [2].

This article will introduce the new features from PHP 5.2 to PHP 5.6.

  • PHP 5.2 before: autoload, PDO and MySQLi, type of constraints
  • PHP 5.2: JSON support
  • PHP 5.3: Abandoned features, anonymous functions, new magic methods, namespace, late static binding, Heredoc, Nowdoc, const, ternary operator, Phar
  • PHP 5.4: Short Open Tag, new syntax of array, Traits, built-in web server, small features changes
  • PHP 5.5: yield, list() in foreach, feature changes
  • PHP 5.6: constant scalar expressions, Variadic functions and argument unpacking, namespace enhancement

Read More

I’ve been a software developer for more than 5 years time. Over the past few years, I have greatly improved my development and communication skills. As the technologies keep updating days by days, I always worry my programming knowledge won’t be enough. Sometimes I doubt if I have fallen behind the industry.

In order to find out what I should learn next for my career, I am in favour of joinging the technical meetups as much as I can. As far as I can find from the conversations during the meetups, I realised I had to get in the habit of writing blogs occasionally to record what I have learnt from work. Because it would be much easier to find out the same question from my blog than google it again.

I believe I can learn more from writing technical blogs than keep reading the new books with nothing else.

Therefore, I should keep posting at least once per week. Keep fighting. (^o^)