Dave James Miller

Developer. Computer Geek. INTJ.



Laravel’s Dependency Injection Container in Depth

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn’t cover all of the available functionality, so I decided to experiment with it and document it for myself. Read More

PHP CLI script that can also be run in a web browser

I had a command line (CLI) script written in PHP that I wanted to be able to run via the web, to save having to open a terminal and SSH connection each time. Read More

Display a list of a user’s Gists in WordPress

This code creates a shortcode, [gists], which displays a list of all Gists by a user, grouped into categories then listed alphabetically. Read More

Installing PHP 5.4 on Debian 6 (Squeeze)

Debian 7 (Wheezy) is due to come out soon, but I didn’t want to wait to upgrade to PHP 5.4, nor to install the release candidate. I tried using the Wheezy repository, but got dependency errors. Fortunately Dotdeb provides packages for… Read More

Installing PHP 5.2 FastCGI on a cPanel server (alongside PHP 5.3+)

This is based on my instructions for Debian and a bit from this forum post. It requires root access and you must be comfortable using the command line. Read More

Write to standard output/error streams in PHP CLI

How to write to STDOUT and STDERR in PHP. Read More

Recursively copy a directory, including symlink support, in PHP

function copy_dir($src, $dst) Read More

Recursively delete a directory, including symlink support, in PHP

function delete_dir($dir) Read More

Get HTTP redirect destination for a URL in PHP

Makes a HTTP request and read the Location header(s) to determine the redirect destination. Read More

Resize an image on the fly with PHP and cache it (like Drupal’s ImageCache)

This script takes an image and resizes it to the given dimensions, then saves that version on the filesystem so Apache can serve it directly in the future. Read More

Zip a dynamically generated file in PHP

// Generate the contents of the file somehow $content = '...'; // Zip the file $zipFile = tempnam(sys_get_temp_dir(), 'zipfile'); $zip = new ZipArchive; $zip->open($zipFile, ZipArchive::OVERWRITE); $zip->addFromString('sample.txt', $content); $zip->close(); // Do something with the file (e.g. attach it to an email)… Read More

Installing PHP FastCGI with suEXEC on Debian

Most of the time I’m happy with mod_php. It’s certainly the most efficient way to run PHP. But there is one major downside – all scripts are run as the Apache user (www-data). We can get around this by using… Read More

HTML to PDF conversion in PHP using wkhtmltopdf (and Smarty)

Recently I was asked to generate PDF invoices for an online shop. I looked at various PHP PDF generators, but wasn’t particularly impressed with any of them. Then I found (via Stack Overflow) a command-line HTML-to-PDF convertor called wkhtmltopdf, which… Read More

Connecting PHP to Microsoft SQL Server on Linux

Here is how to get PHP 5.2 on Linux (specifically Debian/Ubuntu) talking to a Microsoft SQL Server database Read More

Installing PHP 5.2 FastCGI on Debian 6 (Squeeze)

Debian Squeeze comes with PHP 5.3. This is good, because PHP 5.2 is no longer maintained, but causes problems for old applications that can’t support it (e.g. ViArt 3, because it uses Zend Encoder). Rather than permanently downgrade PHP for the whole server,… Read More

Get the domain name from a URL for display purposes in PHP

This is a very simple function to convert a user-supplied URL to just the domain name. Read More

© 2017 Dave James Miller — Powered by WordPress

Theme by Anders NorenUp ↑