Browsed by
Category: PHP

Observer Design Pattern

Observer Design Pattern

The Observer Design Pattern defines a one to many dependency between objects such that when one object changes state all of its dependants are notified and updated automatically. The observer design pattern is a really simply, yet incredibly useful pattern. You’ll already be familiar with how it works. Imagine you want to be kept informed of the weather updates for your area (or if you’re in South Africa – Eskom se push!). You download your favourite weather app and subscribe…

Read More Read More

Linked Lists

Linked Lists

Linked lists are a data structure in which the data nodes are linked together via pointers. Pointers point to something. In this case a node points to another node. Linked lists are useful in building up other data structures like binary search trees etc. In this blog we’re not going to use pointers to memory as we would in a language like c, we’re rather going to emulate this with simple arrays. We’re going to discuss then extremely briefly and…

Read More Read More

Web sockets | real time communication between front and back ends

Web sockets | real time communication between front and back ends

NOTE: I have a new post in the pipeline about web sockets using Laravel’s Reverb which is new in Laravel 11 as well as Laravel’s echo on the front end. I will include a link to that post here once its up. This is a more general post so perfectly usable in PHP without a framework. Its been a while since I’ve written a post and this is a good one (if I do say so myself!). In today’s fast-paced…

Read More Read More

Auto Loading in PHP

Auto Loading in PHP

Auto loading in PHP is the means by which to load classes (and traits and things!) without needing to specifically require the class file. On smaller projects with one or two classes and a handful of files this might not seem like a big deal, but on larger project, particularly with classes from different vendors, and in frameworks like Laravel, auto loading becomes particularly important. Our file structure To follow this PHP autoloading tutorial you should be aware of our…

Read More Read More

Using Composer Dependency Manager

Using Composer Dependency Manager

In days gone by when you wrote a project in PHP you would often write all parts of the project yourself, or you probably had code components from previous projects that you copy and pasted into your new project. You may even have gotten a third party library from the web. Of course in these days gone by you also had to figure out how to load the code into your new project. Composer Dependency Manager came along and changed…

Read More Read More

Facebook Share Button Missing Image

Facebook Share Button Missing Image

  On one of my client’s sites they have the regular social sharing icons. When a visitor clicks on the share to facebook link it populates that share with some default info, and very importantly the image. This is important to them because they run image voting sites. I was asked to see if I could fathom why the image was missing on facebook sharing. The first thing I checked was the open graph (OG) tags on the site. The…

Read More Read More

PHP Traits

PHP Traits

What are PHP traits? In genetics, traits refer to a characteristic or an attribute in your DNA. For instance, you have a trait for eye colour, or hair type. In PHP traits refer to a set of common functions which can be used by multiple classes. I think of it almost as “includes for classes” (don’t quote me on that, its just a conceptual way of looking at it). As with most programming languages, PHP is easiest learned by example,…

Read More Read More

Dependency Injection

Dependency Injection

Dependency injection is a design pattern which allows you to inject your dependencies into a class, rather than have them loaded from within that class. This blog post on PHP dependency injection will be an example based post without too much commentary from me.   Typically when we write our classes they require functionality from other classes. One way of achieving this is to include and load a new instance of the dependency within our class. Another possibility is that…

Read More Read More

Zend Opcache improves page load speed

Zend Opcache improves page load speed

Zend Opcache in PHP improves your page speed by compiling code into machine code and storing the byte code in RAM. With each subsequent hit to a resource code is served from memory rather than being compiled again. PHP is an interpreted language. What this means is that unlike languages like C / C++, PHP is not compiled once to machine code and then executed from the binary each time. With PHP, each time a page is viewed on your…

Read More Read More

PHP Queues with php-resque

PHP Queues with php-resque

If you’ve been doing PHP development for more than a week you’ll have heard about the benefits of message queues. If you’re totally new to this world and have not heard of queues you should google for more info. At its most basic though a message queue allows your application to offload long running tasks to be completed as background tasks, thus speeding up the front end for your visitors. For instance, on cutestix.co.za (a children’s photo competition site) when…

Read More Read More