Category: PHP

Information and howto articles for PHP

PHP is a powerful open source server-sided scripting language that can be used on a wide variety of operating systems and webservers, including Apache on UNIX and IIS on Windows.

PHP contains numerous extensions which enable you to dynamically create images and flash files, parse xml, connect to remote servers using pop, imap, ftp, http and raw sockets, natively access many database servers including PostgreSql, MySQL and Microsoft SQL Server, compress and decompress files, lookup domain names and and much more.

PHP has an excellent manual and online documentation which covers every function for every extension available.

PHP upload_max_filesize and nginx

I’ve recently set up a new server with PHP & Nginx using packages from dotdeb. The default upload_max_filesize and post_max_size for this setup with php-fpm is 2M. To adjust it, the Nginx config also needs a configuration change, otherwise you’re still stuck with a 2MB limit.

Read More »

PHP email message class for extracting attachments

I've done a bit of work in the past extracting attachments from email with PHP and posted a few articles here showing how to do it. None of them have really been all that satisfactory and so a little earlier this year I started again from scratch. I've posted here what is a work-in-progress due to requests from several people. It's not complete but it does work.

Read More »

PHP $_SERVER variables – CLI via SSH vs cron

I have a number of batch processes that run using PHP as the command interpreter, and discovered after making a change to one of them the other day that the variables available to PHP in the $_SERVER superglobal are different depending on whether it’s run via an SSH session or cron. This post shows the difference on Debian 6. The values available are probably the same on other distros.

Read More »

Fetch message parts into a flat array with PHP IMAP

The PHP IMAP functions imap_fetchstructure and imap_fetchbody are used to work out the structure of an email and get the message body and attachments, but they can be fiddly to use because the message parts can be nested. This post has a function which effectively flattens the message parts into a new array, indexed by the part number which can be directly passed to imap_fetchbody.

Read More »

Escape characters in the PHP date function

It’s funny when you’ve been programming in a language for a long time and fall into odd assumptions about particular functions. For some reason I appear to have assumed there was no way to escape characters in PHP’s date function. Then yesterday I saw some sample code where a character was escaped and double checked in the manual. Sure enough, you can escape characters and it’s obvious. I just thought I’d share it here in case you’re making the same mistake I was.

Read More »