PHP on the Command Line

27 March 2022 php software-engineering

Most people tend to associate PHP with web programming. They might be unaware that PHP is actually great language for shell scripts and command-line use as well. The syntax is relatively expressive so you can do a lot in just a few lines of code. And like Bash, you can just write a script and run it. This is ideal for quickly writing small scripts and leads to faster development than compiled or strictly-typed languages like Go and C#. PHP is also faster than Python which is apparently commonly used for shell scripting.

Static Website Generator

I have not been updating my website and blog in a while. Part of the reason is that I was not fully satisfied with the software powering the site. The site was running on Grav CMS, and don't get me wrong, it is a great piece of software for hosting a website. With Grav all the content of the website is stored in Markdown files and having a database is not required. I much prefer Markdown files since they are a joy to edit and can be stored in a Git repository to keep version history. It suited my preferences much more than something like Wordpress and it was more lightweight also.

Customizing Indentation in Emacs CC Mode

25 October 2020 emacs php software-engineering

I have been using Emacs as my main text editor for writing PHP code. For that purpose, the php-mode is a nice Major Mode which provides syntax highlighting and other convenient features. It can be installed from the MELPA package repository.

Writing a Lisp Interpreter

24 October 2020 php lisp software-engineering

There comes a time in the life of a serious software engineer when he wants to implement a custom programming language. Not with the goal of creating a language that gains widespread adoption (there are enough programming languages already), but as an exercise to gain deeper insight into how programming languages work.

Optimizing PHP: Sorting

12 January 2020 php software-engineering

In the previous post we examined the potential performance issues with nested for-loops and how they can be improved using array lookups instead. Another common pitfall in terms of performance can be sorting when done incorrectly which we will examine here.

Optimizing PHP: Array Lookups Instead of Nested Loops

11 January 2020 php software-engineering

One of the most common issues that I see almost daily when reviewing code is nested loops where they aren't required. They are particularly tricky because they are not slow with small data sets (which developers often use for testing), but become slow in production environment where data sets are larger. Of course, testing with too small data sets is a separate problem which should be fixed as well.

Generic Utility Functions for PHP

16 December 2019 php software-engineering

On this post I would like to introduce some generic utility functions for PHP. I often keep these in the global namespace because they are so useful. You may wish to wrap them in a namespace, or even a class, depending on your use case. They follow similar naming convention as the built-in functions of PHP because I view them almost like extensions to the standard library.

Profiling PHP using Xdebug and Webgrind

15 December 2019 php software-engineering

Have you ever encountered a situation where the performance of your PHP script is not great, but you are not sure where the problem is? Then you try to guess and change some part blindly just to see if that would help?