PHP Articles

Increase memory limit for Composer

Gone are the days of stitching together disparate services in an effort to create a solid continue integration and deployment pipeline. GitLab has had it’s Runners for a while and recently GitHub stepped into the mix with their Actions offering. Because of this, using external services like Travis CI or […]

Only run step for specific version with GitHub Actions

With my recent exploration of GitHub Actions, I’ve had to figure out things that I’ve already figured out with other systems like GitLab Runners and Travis CI. One such thing is conditionally running steps. For things like code coverage, I’m only interested in sending off the coverage report to the […]

How to loop through all files in an S3 bucket in PHP

Recently I decided to finally tackle the ever growing S3 bucket for the niche social network I run. The reason it’s ever growing is because I never implemented any sort of hard deletion logic. At one point, I was planning to move the images over to soft deletions, but never […]

Symlinks with Nginx and PHP-FPM

Recently I’ve been putting time into rebuilding the server infrastructure for Holiday API. This has included hardening the system to be more fault tolerant and building out a new cluster of web servers. The biggest improvement was [finally] introducing a continuous deployment pipeline to complement the existing continuous integration flow. […]

How to calculate United States holiday observances

Usually around a holiday I will do a post that’s somehow related to the holiday. Seemed kind of silly to do a post on how to calculate Independence Day in the United States since it’s pretty straight forward. It always lands on the 4th day of the month of July. […]

How to POST to a webhook in 5 different programming languages

With the release of inbound webhooks for CrowdSync workflows last week, it seemed fitting to do a write up on how to POST to a webhook. So what is a webhook, anyway? The Wikipedia definition is that webhooks are “used-defined HTTP callbacks”. Kind of a stuffy definition if you ask […]

URL routing in PHP

The other day I was checking out what folks are querying to get to my site. Of course a ton of people get here looking for VPS comparison, but what surprised me was the volume of queries for “PHP routing”. Back in 2015 I had posted a basic page rounding […]

PHPUnit with multiple versions of PHP and HHVM on Travis CI

Recently I was updating my PHP Lorem Ipsum library in an attempt to get it testing on HHVM on Travis CI alongside the other versions of PHP I was testing against. Incidentally, the last time I had worked on the project, I had to work out some kinks with older […]

Upgrade to PHP 7.x on Ubuntu 14.04 LTS

Upgrading to PHP 7.x (7.0 or 7.1 as of the time of this writing) is just as easy as it is to upgrade to PHP 5.6! Before we install PHP 7.x, I would recommend getting your system up to date: sudo apt-get update Next you will need to add the […]

I beat PHP and so can you!

By request from Bill Martin, an abridged history of my relationship with the bastard child of programming languages, PHP. Ahh PHP. I love it. I hate it. For well over a decade, I slung PHP day and night. I got into PHP at the tail end of version 3. Prior […]

Reading a specific line from a file with PHP

As I’ve been building a system that is driven primarily by CSV files (because it’s easier to use Google Sheets than it is to build out an admin section) I’ve had to get creative. Recently I found myself working with a CSV file that’s around of 3000 lines of data […]

Convert Mongo BSONDocument to an array in PHP

Ran into a scenario this weekend where I needed to take a sub-document from Mongo but I needed it in an array in PHP. Reading the data from Mongo with PHP was simple and won’t be discussed. What I’d like to talk about is taking the BSONDocument that Mongo returns […]

Programming the same thing in multiple programming languages

Recently I set out on an interesting journey. I wanted to build programming libraries for my API, HolidayAPI. Some of the languages I know like the back of my hand. Others, have never even touched them before. Before you start sending me hate comment, I am fully aware of Swagger. […]

Get the day of the week from a date in PHP

Typical of PHP, it’s very easy to get the day of the week from a date, but they also provide the data in multiple format. Three in fact. The first, and arguably the most straight forward is to get the textual name of the day of the week. <?php echo […]

Calculate time left in day in PHP

Before PHP 5.3, finding the difference between two dates was a bit of a pain. Convert the date strings to UNIX timestamps (if they weren’t already), subtract them, and then divide the result until you had each of the components (seconds, minutes, et cetera). As of PHP 5.3+ you can […]

Email validation via MX lookup in PHP

Validating that an email addresses ain’t what it used to be. I remember writing simple regular expressions that worked out really well. These days there are a bajillion TLDs with more being added all of the time. Something I started doing is checking that the domain of the email being […]

Check if a string contains a character with PHP

Checking if a string contains a character could be accomplished easily with a regular expression or you can use the built-in PHP functions. To check if a string contains a character of a specific case you can use strpos. $haystack = 'This is my haystack that we shall check' $has_A […]

Generate random hex color with PHP

There’s many ways to skin a cat, or generate a color. You could randomize a number between 0 and 16777215 then convert it to hex: $rand_color = '#' . dechex(mt_rant(0, 16777215)); Or you could do what I like to do, just md5 a random string and grab the first 6 […]

Run a block of PHP code a certain percentage of the time

Sometimes, you may want to run code all of the time. Other times, you may want to run code some of the time. This is how garbage collection in PHP works. Based on your configuration for gc_probability and gc_divisor, garbage collections runs a fraction of the time (defaulting to 1/100 […]

PHP is stupid and so are you

I hope you’re really fucking pissed right now. I hope you go thermonuclear on the comments box. Why? Because it really just proves how right I am about how stupid you are. You let some silly blog post get under your skin. Thing is, I really didn’t know what to […]

Detect bots and spammers with Project Honey Pot and PHP

Project Honey Pot is one of my favorite services. They offer an API that allows you to pull information on an IP address. This comes in very handy when vetting traffic coming to your website. I discovered the service a few years back after realizing that I had some spammers […]

How to convert a string to a time with PHP

Converting a string to a timestamp is one of my favorite things about PHP. In fact when trying to decide which language to build [HolidayAPI][holidayapi] in I couldn’t find an implementation of PHP’s strtotime() that rivaled the original. The strtotime() function takes a textual string as input and then spits […]

Set array pointer to a specific key or value in PHP

PHP arrays are absolutely fantastic. They hold stuff, doesn’t really matter what. The interfacing is pretty consistent and there’s a boat load of built-in array functions. What PHP lacks is the ability to set the array pointer to an arbitrary key or value. There are ways to move forward and […]

Basic page routing in PHP

Last week we talked about setting up a local development server with PHP’s built-in web server and I mentioned that we’d delve into page routing. Routing refers to taking the URI that a person was requested, let’s say /about and routing that to the appropriate code. Sure, you could just […]

Using PHP's built-in web server

I recently updated [HolidayAPI][holidayapi] to no longer use my PHP framework because I wanted the system to be easier for new developers to get up and running. Instead of including configuration files for Apache or nginx, I decided that I should just use the web server that’s baked right into […]