This past weekend, I started playing with GitHub Pages for the first time. It took a while to figure out, but was somewhat fun. I’ve been interested in it for a while, but was unsure of how to do what I wanted, such as building with PHP, Sass, and Rollup. Turns out it was fairly easy with GitHub Actions to do most any sort of build steps I want. It is very interesting for free static site web-hosting.Continue reading post "Playing with GitHub Pages"
Swap file for composer out of memory problems
PHP’s defacto package manager, composer, has long required large amounts of memory to do updates for larger projects, often more than servers or virtual machines have. The script will die with an out of memory error, or more recently, the simple message “Killed”, and do no work in these situations. The normal procedure is to develop locally, deploy local lock file (
composer.lock) to the server, and run
composer install instead of
update. But I’ve recently moved to doing most of my development in VMs, so I have had to work around this problem to get things installed or updated. A swap file is the solution for Linux machines provided in the official docs and expanded in a StackOverflow answer.
Sorting with `FIELD()` function in Doctrine
I recently needed to sort query results to match the order of IDs passed to it for use in a
WHERE … IN() clause. In MySQL, this can be done using the
FIELD() function in the
ORDERY BY clause. For Doctrine, which doesn’t have the
FIELD() function and doesn’t allow functions in the
ORDER BY clause, there’s a little more work needed to make use of it.
PHP-FPM / Apache caching symlinks
At Cogneato, we use symlinks to point the web server to different versions of our software for websites. Sometimes, especially on our Ubuntu server, which uses PHP-FPM to serve PHP files through Apache, I was noticing problems caused by scripts being loaded from the previous symlink destination when I changed to the new one. There seems to be some sort of caching going on. The solution was to restart PHP-FPM and Apache after switching the symlinks. On Ubuntu, this looks like:
ln -s /path/to/new-version /path/to/software-link \ && sudo service php7.2-fpm restart \ && sudo service apache2 graceful
7.2 is the version of PHP being used. Haven’t noticed the problem since.
Deploying updates to my site with a composer lock file seemed slower since updating to version 2, so maybe it isn’t faster in some circumstances.
I see that
composer has released its 2.0 version. Nice.
PHP: Escaping email display name
I recently had the need to take a name from a form submission and use it as the display name of the “From” address of an email sent through PHP’s
mail() function. For an address like
Toby Example <firstname.lastname@example.org>, the display name is the
Toby Example part.
Automatically reconnect PDO when connection times out
In PHP scripts that run queries to a MySQL database over a long period of time, the connection may time out and give a “MySQL server has gone away” error.Continue reading post "Automatically reconnect PDO when connection times out"
Import SQL file in Doctrine / PDO
I recently needed to programmatically import SQL files containing database dumps into a database managed by Doctrine ORM.Continue reading post "Import SQL file in Doctrine / PDO"
New server setup at Cogneato
I’m kind of excited that we moved the first site onto a new server setup at Cogneato. I had worked off and on on the setup for months before we finally went forward with it. It brings a new OS, new host, new software, and a number of other changes to our previous setup.Continue reading post "New server setup at Cogneato"